Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed myUSBHost AvailableMemory
Dependents: mbed_TANK_Kinect myBlueUSB_ros ftusbClass
Diff: neighbourhood.h
- Revision:
- 6:567607a9a79f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/neighbourhood.h Sat Jun 11 19:45:42 2011 +0000
@@ -0,0 +1,77 @@
+#ifndef NEIGHBOURHOOD_H
+#define NEIGHBOURHOOD_H
+
+#include <list>
+#include "hci.h"
+
+//#define STRICT_MRU
+
+/******************************************************************************************
+call 'read' as part of the startup
+on HCI_READ-STORED-LINK-KEY -COMPLETED event, call 'set_cap'
+on RETURN_LINK_KEYS_EVENT call 'add' for each key with init=true
+on LINK_KEY_NOTIFICATION_EVENT call 'add' with init=false (default)
+on LINK_KEY_REQUEST_EVENT call 'get' and send the proper reply
+call 'write' as part of shutdown
+
+a simpler approach could be to check for a link if it exists (single read) and try to add it.
+when it fails just delete all.
+********************************************************************************************/
+
+#define HCI_DELETE_STORED_LINK_KEY 0x0C12
+#define HCI_WRITE_STORED_LINK_KEY 0x0C11
+#define HCI_READ_STORED_LINK_KEY 0x0C0D
+
+void printf(const BD_ADDR* addr);
+
+class neighbourhood {
+ static const int lksize = 16;
+ struct item {
+ BD_ADDR a;
+ unsigned char lk[lksize];
+ bool used;
+ item (BD_ADDR *ad, const unsigned char *k, bool d) {
+ memcpy(&a, ad, sizeof(BD_ADDR));
+ memcpy(lk, k, lksize);
+ used=d;
+ }
+ };
+ int cap, initsize, used;
+ list<item> keys;
+ bool dirty;
+ HCI *hci;
+ void delete_link_key(BD_ADDR *a) {
+ unsigned char param[sizeof(BD_ADDR)+1];
+ memcpy(param, a, sizeof(BD_ADDR));
+ param[sizeof(BD_ADDR)] = 0;
+ hci->SendCmd(HCI_DELETE_STORED_LINK_KEY, param, sizeof(param));
+ }
+ void write_link_keys(unsigned char param[]) {
+ hci->SendCmd(HCI_WRITE_STORED_LINK_KEY, param, param[0]*(sizeof(BD_ADDR)+lksize)+1);
+ }
+public:
+ neighbourhood(HCI *h): hci(h) {
+ dirty = false;
+ used = 0;
+ cap=0;
+ initsize=0;
+ }
+ void read() {
+ unsigned char param[sizeof(BD_ADDR)+1];
+ memset(param, 0, sizeof(BD_ADDR));
+ param[sizeof(BD_ADDR)] = 1;
+ hci->SendCmd(HCI_READ_STORED_LINK_KEY, param, sizeof(param));
+ }
+ void write();
+ void set_cap(int c, int s) {
+ cap = c;
+ initsize = s;
+ printf("Neighbourhood: capacity=%d, used=%d\n", c, s);
+ }
+ int get(BD_ADDR *a, unsigned char *key);
+ int add(BD_ADDR *a, const unsigned char *key, bool init=false);
+};
+
+extern neighbourhood *neighbors;
+
+#endif
\ No newline at end of file