Takashi Ogura / Mbed 2 deprecated myBlueUSB_ros

Dependencies:   mbed myUSBHost AvailableMemory myBlueUSB

Committer:
OTL
Date:
Sat Sep 17 14:24:13 2011 +0000
Revision:
1:18139954944b
Parent:
0:7684b95768c7
remove m3pi and main

Who changed what in which revision?

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