local fix version of myBlueUSB (http://mbed.org/users/networker/code/myBlueUSB/). - merge deleted files which are required to compile. - enable echo back of received data via RFCOMM.

Dependencies:   AvailableMemory FatFileSystem mbed myUSBHost

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers neighbourhood.h Source File

neighbourhood.h

00001 #ifndef NEIGHBOURHOOD_H
00002 #define NEIGHBOURHOOD_H
00003 
00004 #include <list>
00005 #include "hci.h"
00006 
00007 //#define STRICT_MRU
00008 
00009 /******************************************************************************************
00010 call 'read' as part of the startup
00011 on HCI_READ-STORED-LINK-KEY -COMPLETED event,  call 'set_cap'
00012 on RETURN_LINK_KEYS_EVENT call 'add' for each key with init=true
00013 on LINK_KEY_NOTIFICATION_EVENT call 'add' with init=false (default)
00014 on LINK_KEY_REQUEST_EVENT call 'get' and send the proper reply
00015 call 'write' as part of shutdown
00016 
00017 a simpler approach could be to check for a link if it exists (single read) and try to add it.
00018 when it fails just delete all.
00019 ********************************************************************************************/
00020 
00021 #define HCI_DELETE_STORED_LINK_KEY  0x0C12
00022 #define HCI_WRITE_STORED_LINK_KEY   0x0C11
00023 #define HCI_READ_STORED_LINK_KEY    0x0C0D
00024 
00025 void printf(const BD_ADDR* addr);
00026 
00027 class neighbourhood {
00028     static const int lksize = 16;
00029     struct item {
00030         BD_ADDR a;
00031         unsigned char lk[lksize];
00032         bool used;
00033         item (BD_ADDR *ad, const unsigned char *k, bool d) {
00034             memcpy(&a, ad, sizeof(BD_ADDR));
00035             memcpy(lk, k, lksize);
00036             used=d;
00037         }
00038     };
00039     int cap, initsize, used;
00040     list<item> keys;
00041     bool dirty;
00042     HCI *hci;
00043     void delete_link_key(BD_ADDR *a) {
00044         unsigned char param[sizeof(BD_ADDR)+1];
00045         memcpy(param, a, sizeof(BD_ADDR));
00046         param[sizeof(BD_ADDR)] = 0;
00047         hci->SendCmd(HCI_DELETE_STORED_LINK_KEY, param, sizeof(param));
00048     }
00049     void write_link_keys(unsigned char param[]) {
00050         hci->SendCmd(HCI_WRITE_STORED_LINK_KEY, param, param[0]*(sizeof(BD_ADDR)+lksize)+1);
00051     }
00052 public:
00053     neighbourhood(HCI *h): hci(h) {
00054         dirty = false;
00055         used = 0;
00056         cap=0;
00057         initsize=0;
00058     }
00059     void read() {
00060         unsigned char param[sizeof(BD_ADDR)+1];
00061         memset(param, 0, sizeof(BD_ADDR));
00062         param[sizeof(BD_ADDR)] = 1;
00063         hci->SendCmd(HCI_READ_STORED_LINK_KEY, param, sizeof(param));
00064     }
00065     void write();
00066     void set_cap(int c, int s) {
00067         cap = c;
00068         initsize = s;
00069         printf("Neighbourhood: capacity=%d, used=%d\n", c, s);
00070     }
00071     int get(BD_ADDR *a, unsigned char *key);
00072     int add(BD_ADDR *a, const unsigned char *key, bool init=false);
00073 };
00074 
00075 extern neighbourhood *neighbors;
00076 
00077 #endif