![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork to force BLE id to have prefix that is assumed by the app
Dependencies: BLE_API Crypto RNG mbed nRF51822
Fork of Garagem by
Diff: main.cpp
- Revision:
- 10:80850cd6c29e
- Parent:
- 9:329af8cdc923
- Child:
- 11:3de9b542eeac
diff -r 329af8cdc923 -r 80850cd6c29e main.cpp --- a/main.cpp Tue Aug 25 22:18:21 2015 +0000 +++ b/main.cpp Tue Aug 25 23:26:43 2015 +0000 @@ -32,7 +32,12 @@ //how-to test: //create a string to write to the characteristic -//openssl enc -aes-128-cbc -K 9734062BA852A049CF5D40593B769014 -iv A2685636521871D02306E2EB8F7027B3 -out /dev/stdout +//openssl enc -aes-128-cbc -K 9734062BA852A049CF5D40593B769014 -iv A2685636521871D02306E2EB8F7027B3 -out /dev/stdout -in inputfile +// TTTTIIIISSSSSSSS +// T -> 4 bytes Timestamp uint32_t +// I -> 4 bytes ID (chars) +// S -> 8 bytes SHARED_SECRET (chars) + #define SHARED_KEY "figueiredo" #define DEVICE_NAME "Garagem" //openssl enc -aes-128-cbc -pass pass:********** -nosalt -P @@ -72,28 +77,29 @@ */ void onDataWrittenCallback(const GattWriteCallbackParams *params) { DBG("onDataWrittenCallback: handle = %d len = %d\r\n", params->handle, params->len); - + garagemServicePtr->nextLastOpen(params->data, params->len); + if ((params->handle == garagemServicePtr->getChallengeHandle()) && (params->len ==16)) { - DBG("onDataWrittenCallback: data = %s\r\n", (char *) (params->data)); - actuatedLED = !actuatedLED; + DBG("We have Challenge: data = %s\r\n", (char *) (params->data)); AES myAES(AES_128, myKey, iv); uint8_t msg[16]; myAES.decrypt(msg,(uint8_t *) (params->data),16); if(garagemServicePtr->checkMessage(msg) == GARAGEM_OK) { + DBG("ABRE-TE SESAMO!\r\n"); + #ifndef DEBUG relay = 1; #endif - DBG("ABRE-TE SESAMO!\r\n"); - + actuatedLED = !actuatedLED; //please cleanup afterwards offRelay.attach(&switchOffRelay, 1.0); } else { DBG("NO SUCH LUCK...\r\n"); } - } + } } int main(void)