Skip to content

Commit 1ab707d

Browse files
committed
set static passkey
1 parent 32b7d19 commit 1ab707d

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

src/BLEDevice.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "BLEDevice.h"
77

8+
#include <ble.h>
9+
810
#define DEFAULT_ADVERTISING_INTERVAL 100
911
#define DEFAULT_CONNECTABLE true
1012

@@ -24,6 +26,7 @@ BLEDevice::BLEDevice() :
2426
}
2527

2628
BLEDevice::~BLEDevice() {
29+
2730
}
2831

2932
void BLEDevice::setEventListener(BLEDeviceEventListener* eventListener) {
@@ -58,3 +61,9 @@ void BLEDevice::sendPasskey(char passkey[]){
5861
void BLEDevice::confirmPasskey(bool confirm){
5962
this->_userConfirm = confirm;
6063
}
64+
65+
void BLEDevice::setStaticKeysOpt(char* key){
66+
static ble_opt_t m_static_pin_option;
67+
m_static_pin_option.gap_opt.passkey.p_passkey = (uint8_t*) key;
68+
int err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option);
69+
}

src/BLEDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class BLEDevice
8080
void setBondStore(BLEBondStore& bondStore);
8181
void sendPasskey(char passkey[]);
8282
void confirmPasskey(bool confirm);
83+
void setStaticKeysOpt(char* key);
84+
8385

8486
virtual void begin(unsigned char /*advertisementDataSize*/,
8587
BLEEirData * /*advertisementData*/,

src/BLEPeripheral.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ void BLEPeripheral::sendPasskey(char passkey[]){
233233
this->_device->sendPasskey(passkey);
234234
}
235235

236+
void BLEPeripheral::setStaticPasskey(char passkey[]){
237+
this->_device->setStaticKeysOpt(passkey);
238+
}
239+
236240
void BLEPeripheral::confirmPasskey(bool confirm){
237241
this->_device->confirmPasskey(confirm);
238242
}

src/BLEPeripheral.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class BLEPeripheral : public BLEDeviceEventListener,
9999
void enableBond(BLEBondingType type = JUST_WORKS);
100100
char *getPasskey();
101101
void sendPasskey(char passkey[]);
102+
void setStaticPasskey(char passkey[]);
102103
void confirmPasskey(bool confirm);
103104

104105

0 commit comments

Comments
 (0)