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
neigbourhood/neighbourhood.h@2:9f25a7fa1a54, 2013-12-08 (annotated)
- Committer:
- nobukuma
- Date:
- Sun Dec 08 21:52:09 2013 +0000
- Revision:
- 2:9f25a7fa1a54
- Parent:
- 0:003889bc474f
???BT??????????????????; ?????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nobukuma | 0:003889bc474f | 1 | #ifndef NEIGHBOURHOOD_H |
nobukuma | 0:003889bc474f | 2 | #define NEIGHBOURHOOD_H |
nobukuma | 0:003889bc474f | 3 | |
nobukuma | 0:003889bc474f | 4 | #include <list> |
nobukuma | 0:003889bc474f | 5 | #include "hci.h" |
nobukuma | 0:003889bc474f | 6 | |
nobukuma | 0:003889bc474f | 7 | //#define STRICT_MRU |
nobukuma | 0:003889bc474f | 8 | |
nobukuma | 0:003889bc474f | 9 | /****************************************************************************************** |
nobukuma | 0:003889bc474f | 10 | call 'read' as part of the startup |
nobukuma | 0:003889bc474f | 11 | on HCI_READ-STORED-LINK-KEY -COMPLETED event, call 'set_cap' |
nobukuma | 0:003889bc474f | 12 | on RETURN_LINK_KEYS_EVENT call 'add' for each key with init=true |
nobukuma | 0:003889bc474f | 13 | on LINK_KEY_NOTIFICATION_EVENT call 'add' with init=false (default) |
nobukuma | 0:003889bc474f | 14 | on LINK_KEY_REQUEST_EVENT call 'get' and send the proper reply |
nobukuma | 0:003889bc474f | 15 | call 'write' as part of shutdown |
nobukuma | 0:003889bc474f | 16 | |
nobukuma | 0:003889bc474f | 17 | a simpler approach could be to check for a link if it exists (single read) and try to add it. |
nobukuma | 0:003889bc474f | 18 | when it fails just delete all. |
nobukuma | 0:003889bc474f | 19 | ********************************************************************************************/ |
nobukuma | 0:003889bc474f | 20 | |
nobukuma | 0:003889bc474f | 21 | #define HCI_DELETE_STORED_LINK_KEY 0x0C12 |
nobukuma | 0:003889bc474f | 22 | #define HCI_WRITE_STORED_LINK_KEY 0x0C11 |
nobukuma | 0:003889bc474f | 23 | #define HCI_READ_STORED_LINK_KEY 0x0C0D |
nobukuma | 0:003889bc474f | 24 | |
nobukuma | 0:003889bc474f | 25 | void printf(const BD_ADDR* addr); |
nobukuma | 0:003889bc474f | 26 | |
nobukuma | 0:003889bc474f | 27 | class neighbourhood { |
nobukuma | 0:003889bc474f | 28 | static const int lksize = 16; |
nobukuma | 0:003889bc474f | 29 | struct item { |
nobukuma | 0:003889bc474f | 30 | BD_ADDR a; |
nobukuma | 0:003889bc474f | 31 | unsigned char lk[lksize]; |
nobukuma | 0:003889bc474f | 32 | bool used; |
nobukuma | 0:003889bc474f | 33 | item (BD_ADDR *ad, const unsigned char *k, bool d) { |
nobukuma | 0:003889bc474f | 34 | memcpy(&a, ad, sizeof(BD_ADDR)); |
nobukuma | 0:003889bc474f | 35 | memcpy(lk, k, lksize); |
nobukuma | 0:003889bc474f | 36 | used=d; |
nobukuma | 0:003889bc474f | 37 | } |
nobukuma | 0:003889bc474f | 38 | }; |
nobukuma | 0:003889bc474f | 39 | int cap, initsize, used; |
nobukuma | 0:003889bc474f | 40 | list<item> keys; |
nobukuma | 0:003889bc474f | 41 | bool dirty; |
nobukuma | 0:003889bc474f | 42 | HCI *hci; |
nobukuma | 0:003889bc474f | 43 | void delete_link_key(BD_ADDR *a) { |
nobukuma | 0:003889bc474f | 44 | unsigned char param[sizeof(BD_ADDR)+1]; |
nobukuma | 0:003889bc474f | 45 | memcpy(param, a, sizeof(BD_ADDR)); |
nobukuma | 0:003889bc474f | 46 | param[sizeof(BD_ADDR)] = 0; |
nobukuma | 0:003889bc474f | 47 | hci->SendCmd(HCI_DELETE_STORED_LINK_KEY, param, sizeof(param)); |
nobukuma | 0:003889bc474f | 48 | } |
nobukuma | 0:003889bc474f | 49 | void write_link_keys(unsigned char param[]) { |
nobukuma | 0:003889bc474f | 50 | hci->SendCmd(HCI_WRITE_STORED_LINK_KEY, param, param[0]*(sizeof(BD_ADDR)+lksize)+1); |
nobukuma | 0:003889bc474f | 51 | } |
nobukuma | 0:003889bc474f | 52 | public: |
nobukuma | 0:003889bc474f | 53 | neighbourhood(HCI *h): hci(h) { |
nobukuma | 0:003889bc474f | 54 | dirty = false; |
nobukuma | 0:003889bc474f | 55 | used = 0; |
nobukuma | 0:003889bc474f | 56 | cap=0; |
nobukuma | 0:003889bc474f | 57 | initsize=0; |
nobukuma | 0:003889bc474f | 58 | } |
nobukuma | 0:003889bc474f | 59 | void read() { |
nobukuma | 0:003889bc474f | 60 | unsigned char param[sizeof(BD_ADDR)+1]; |
nobukuma | 0:003889bc474f | 61 | memset(param, 0, sizeof(BD_ADDR)); |
nobukuma | 0:003889bc474f | 62 | param[sizeof(BD_ADDR)] = 1; |
nobukuma | 0:003889bc474f | 63 | hci->SendCmd(HCI_READ_STORED_LINK_KEY, param, sizeof(param)); |
nobukuma | 0:003889bc474f | 64 | } |
nobukuma | 0:003889bc474f | 65 | void write(); |
nobukuma | 0:003889bc474f | 66 | void set_cap(int c, int s) { |
nobukuma | 0:003889bc474f | 67 | cap = c; |
nobukuma | 0:003889bc474f | 68 | initsize = s; |
nobukuma | 0:003889bc474f | 69 | printf("Neighbourhood: capacity=%d, used=%d\n", c, s); |
nobukuma | 0:003889bc474f | 70 | } |
nobukuma | 0:003889bc474f | 71 | int get(BD_ADDR *a, unsigned char *key); |
nobukuma | 0:003889bc474f | 72 | int add(BD_ADDR *a, const unsigned char *key, bool init=false); |
nobukuma | 0:003889bc474f | 73 | }; |
nobukuma | 0:003889bc474f | 74 | |
nobukuma | 0:003889bc474f | 75 | extern neighbourhood *neighbors; |
nobukuma | 0:003889bc474f | 76 | |
nobukuma | 0:003889bc474f | 77 | #endif |