Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add load link key types #6

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions btsocket/btmgmt_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,37 @@ def __repr__(self):
ManufacturerData = 0xff


class LinkKeyType(Enum):
def __str__(self):
return str(self.name)

def __repr__(self):
return str(self.name)

Combination = 0x00
LocalUnit = 0x01
RemoteUnit = 0x02
DebugCombination = 0x03
UnauthenticatedCombinationP192 = 0x04
AuthenticatedCombinationP192 = 0x05
ChangedCombination = 0x06
UnauthenticatedCombinationP256 = 0x07
AuthenticatedCombinationP256 = 0x08


class LinkKeyTypeData(DataField):

def decode(self, data):
self.value = LinkKeyType(int.from_bytes(data, byteorder='little'))
self.octets = data

def encode(self, value, width):
self.value = value
self.octets = int(value.value).to_bytes(width,
byteorder='little',
signed=False)


class ErrorCodes(Enum):
def __str__(self):
return str(self.name)
Expand Down Expand Up @@ -578,8 +609,8 @@ def __repr__(self):
Parameter(name='address', width=6, bt_type='Address'),
Parameter(name='address_type', width=1,
bt_type='AddressTypeField'),
Parameter(name='key_type', width=1),
Parameter(name='value', width=16),
Parameter(name='key_type', width=1, bt_type='LinkKeyTypeData'),
Parameter(name='value', width=16, bt_type='HexStr'),
Parameter(name='pin_length', width=1)]),
0x0013: Packet([Parameter(name='key_count', width=2),
Parameter(name='address', width=6, bt_type='Address'),
Expand Down