This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Feature/ble gap device name set #189
Open
dangu
wants to merge
11
commits into
NordicSemiconductor:master
Choose a base branch
from
dangu:feature/ble_gap_device_name_set
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
00370fc
Test read_perm
dangu 2ba9f3c
Use BLEGapConnSecMode object in BLEGattsAttrMD
dangu 0b1cfff
Fix for the user_desc argument of BLEGattsCharMD()
dangu 53639e7
Implement ble_gap_device_name_set()
dangu 6e20502
Merge branch 'master' into feature/ble_gap_device_name_set
bihanssen 916b03e
Merge branch 'master' into feature/ble_gap_device_name_set
kenr 26a0a4e
Merge branch 'master' into feature/ble_gap_device_name_set
jornbh 63eb5b9
Merge branch 'master' into feature/ble_gap_device_name_set
jornbh 945bb20
Use BLEGapConnSecMode methods for setting device name write permissions
dangu 36ceefd
Merge branch 'master' into feature/ble_gap_device_name_set
jornbh 07a262e
Merge branch 'master' into feature/ble_gap_device_name_set
jornbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,63 @@ def to_c(self): | |
|
||
return scan_params | ||
|
||
class BLEGapConnSecMode(object): | ||
def __init__(self, sm=0, lv=0): | ||
self.sm = sm | ||
self.lv = lv | ||
|
||
def set_no_access(self): | ||
"""BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS""" | ||
self.sm = 0 | ||
self.lv = 0 | ||
|
||
def set_open(self): | ||
"""BLE_GAP_CONN_SEC_MODE_SET_OPEN""" | ||
self.sm = 1 | ||
self.lv = 1 | ||
|
||
def set_enc_no_mitm(self): | ||
"""BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM""" | ||
self.sm = 1 | ||
self.lv = 2 | ||
|
||
def set_enc_with_mitm(self): | ||
"""BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM""" | ||
self.sm = 1 | ||
self.lv = 3 | ||
|
||
def set_lesc_enc_with_mitm(self): | ||
"""BLE_GAP_CONN_SEC_MODE_SET_LESC_ENC_WITH_MITM""" | ||
self.sm = 1 | ||
self.lv = 4 | ||
|
||
def set_signed_no_mitm(self): | ||
"""BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM""" | ||
self.sm = 2 | ||
self.lv = 1 | ||
def set_signed_with_mitm(self): | ||
"""BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM""" | ||
self.sm = 2 | ||
self.lv = 2 | ||
|
||
@classmethod | ||
def from_c(cls, sec_mode): | ||
return cls( | ||
sm=sec_mode.sm, | ||
lv=sec_mode.lv, | ||
) | ||
|
||
def to_c(self): | ||
sec_mode = driver.ble_gap_conn_sec_mode_t() | ||
sec_mode.sm = self.sm | ||
sec_mode.lv = self.lv | ||
|
||
return sec_mode | ||
|
||
def __str__(self): | ||
return "sm({0.ssm}) lv({0.lv}))".format( | ||
self | ||
) | ||
|
||
class BLEGapConnSec(object): | ||
def __init__(self, sec_mode, level, encr_key_size): | ||
|
@@ -1289,15 +1346,22 @@ def to_c(self): | |
|
||
class BLEGattsAttrMD(object): | ||
def __init__(self, vloc=driver.BLE_GATTS_VLOC_STACK, | ||
rd_auth=False, wr_auth=False, vlen=1): | ||
rd_auth=False, wr_auth=False, | ||
read_perm=None, write_perm=None, vlen=1): | ||
self.vloc = vloc | ||
self.rd_auth = rd_auth | ||
self.wr_auth = wr_auth | ||
self.read_perm = read_perm | ||
self.write_perm = write_perm | ||
self.vlen = vlen | ||
|
||
def to_c(self): | ||
attr_md = driver.ble_gatts_attr_md_t() | ||
attr_md.vloc = self.vloc | ||
if self.read_perm: | ||
attr_md.read_perm = self.read_perm.to_c() | ||
if self.write_perm: | ||
attr_md.write_perm = self.write_perm.to_c() | ||
attr_md.rd_auth = int(self.rd_auth) | ||
attr_md.wr_auth = int(self.wr_auth) | ||
attr_md.vlen = self.vlen | ||
|
@@ -1387,8 +1451,11 @@ def to_c(self): | |
char_md = driver.ble_gatts_char_md_t() | ||
char_md.char_props = self.char_props.to_c() | ||
if self.user_desc: | ||
char_md.p_char_user_desc = util.list_to_char_array(self.user_desc) | ||
user_desc_array=util.list_to_uint8_array(self.user_desc) | ||
user_desc_array_cast = user_desc_array.cast() | ||
char_md.p_char_user_desc = user_desc_array_cast | ||
char_md.char_user_desc_size = len(self.user_desc) | ||
char_md.char_user_desc_max_size = len(self.user_desc) | ||
if self.pf: | ||
char_md.p_char_pf = self.pf.to_c() | ||
if self.desc_md: | ||
|
@@ -2211,6 +2278,26 @@ def ble_gap_adv_data_set(self, adv_data=BLEAdvData(), scan_data=BLEAdvData()): | |
return driver.sd_ble_gap_adv_data_set( | ||
self.rpc_adapter, p_adv_data, adv_data_len, p_scan_data, scan_data_len | ||
) | ||
|
||
@NordicSemiErrorCheck | ||
@wrapt.synchronized(api_lock) | ||
def ble_gap_device_name_set(self, name, device_name_read_only=True): | ||
write_perm=BLEGapConnSecMode() | ||
if device_name_read_only: | ||
write_perm.sm = 0 | ||
write_perm.lv = 0 | ||
else: | ||
write_perm.sm = 1 | ||
write_perm.lv = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. write_perm.set_open() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok! Now using the BLEGapConnSecMode methods for setting write permissions for the name. Also trying to write a test for ble_gap_device_name_set() |
||
p_write_perm = write_perm.to_c() | ||
p_dev_name = name | ||
p_dev_name = util.list_to_uint8_array([ord(x) for x in name]) | ||
p_dev_name_cast = p_dev_name.cast() | ||
name_length = len(name) | ||
|
||
return driver.sd_ble_gap_device_name_set( | ||
self.rpc_adapter, p_write_perm, p_dev_name_cast, name_length | ||
) | ||
|
||
@NordicSemiErrorCheck | ||
@wrapt.synchronized(api_lock) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be .set_no_access()