void initializeSecurity(BLE &ble) { bool enableBonding = true; bool requireMITM = HID_SECURITY_REQUIRE_MITM; ble.securityManager().onSecuritySetupInitiated(securitySetupInitiatedCallback); ble.securityManager().onPasskeyDisplay(passkeyDisplayCallback); ble.securityManager().onSecuritySetupCompleted(securitySetupCompletedCallback); ble.securityManager().init(enableBonding, requireMITM, HID_SECURITY_IOCAPS); }
void app_start(int, char *[]) { buffer = (uint8_t*)malloc(24); memset(buffer, 0, 24); console.attach(serialHandler); printf("{{end}}\r\n"); // setup buttons // button1.mode(PullUp); // Delay for initial pullup to take effect wait(.01); // button1.fall(button1ISR); // button2.mode(PullUp); // Delay for initial pullup to take effect wait(.01); // button2.fall(button2ISR); /*************************************************************************/ /*************************************************************************/ /* bluetooth le */ ble.init(); // security ble.securityManager().onSecuritySetupInitiated(securityInitiated); ble.securityManager().onSecuritySetupCompleted(securityCompleted); ble.securityManager().onLinkSecured(linkSecured); ble.securityManager().onSecurityContextStored(contextStored); ble.securityManager().onPasskeyDisplay(passkeyDisplay); // connection status handlers ble.gap().onConnection(whenConnected); ble.gap().onDisconnection(whenDisconnected); // set preferred connection parameters to lowest latency Gap::ConnectionParams_t fast; ble.gap().getPreferredConnectionParams(&fast); fast.minConnectionInterval = 16; // 20 ms fast.maxConnectionInterval = 32; // 40 ms fast.slaveLatency = 0; ble.gap().setPreferredConnectionParams(&fast); /* construct advertising beacon */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED|GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *) DEVICE_NAME, sizeof(DEVICE_NAME) - 1); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, uuid.getBaseUUID(), uuid.getLen()); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(200); // Apple uses device name instead of beacon name ble.gap().setDeviceName((const uint8_t*) DEVICE_NAME); // ble setup complete - start advertising ble.gap().startAdvertising(); /*************************************************************************/ /*************************************************************************/ bts = new BlockTransferService(); btc = new BlockTransferClient(); watch = new Timer(); bts->init(uuid, SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK); #if 0 writeBlock.push_back(&writeBlockFragment2); writeBlock.push_back(&writeBlockFragment3); writeBlock.push_back(&writeBlockFragment4); #endif // set callback functions bts->setWriteAuthorizationCallback(blockServerWriteHandler, &receiveBlock); bts->setReadAuthorizationCallback(blockServerReadHandler); printf("BlockTransfer: %s %s %d\r\n", __DATE__, __TIME__, MAX_INDEX_SET_SIZE); }