Skip to content

Commit

Permalink
L2CAP: add command listen_with_mode
Browse files Browse the repository at this point in the history
Add command to listen with the specified
mode.

Signed-off-by: Lyle Zhu <[email protected]>
  • Loading branch information
lylezhu2012 committed Jul 8, 2024
1 parent 64bc445 commit 496c286
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
21 changes: 21 additions & 0 deletions autopts/pybtp/btp/l2cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
CONTROLLER_INDEX),
"cls_send": (defs.BTP_SERVICE_ID_L2CAP, defs.L2CAP_CLS_SEND,
CONTROLLER_INDEX),
"listen_with_mode": (defs.BTP_SERVICE_ID_L2CAP, defs.L2CAP_LISTEN_WITH_MODE,
CONTROLLER_INDEX),
}


Expand Down Expand Up @@ -414,6 +416,25 @@ def l2cap_cls_send(bd_addr, bd_addr_type, psm, val=None, val_mtp=None):
iutctl.btp_socket.send_wait_rsp(*L2CAP['cls_send'], data=data_ba)


def l2cap_listen_with_mode(psm, transport, mode=defs.L2CAP_MODE_BASIC, mtu=0, response=L2CAPConnectionResponse.success):
logging.debug("%s %r %r %r %r %r", l2cap_listen_with_mode.__name__, psm, transport, mode, mtu, response)

iutctl = get_iut()

if isinstance(psm, str):
psm = int(psm, 16)

data_ba = bytearray(struct.pack('H', psm))
data_ba.extend(struct.pack('B', transport))
data_ba.extend(struct.pack('B', mode))
data_ba.extend(struct.pack('H', mtu))
data_ba.extend(struct.pack('H', response))

iutctl.btp_socket.send(*L2CAP['listen_with_mode'], data=data_ba)

l2cap_command_rsp_succ(defs.L2CAP_LISTEN_WITH_MODE)


L2CAP_EV = {
defs.L2CAP_EV_CONNECTED: l2cap_connected_ev,
defs.L2CAP_EV_DISCONNECTED: l2cap_disconnected_ev,
Expand Down
6 changes: 6 additions & 0 deletions autopts/pybtp/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ def BIT(bit):
L2CAP_ECHO = 0x0b
L2CAP_CLS_LISTEN = 0x0c
L2CAP_CLS_SEND = 0x0d
L2CAP_MODE_BASIC = 0x00
L2CAP_MODE_RET = 0x01
L2CAP_MODE_FC = 0x02
L2CAP_MODE_ENH_RET = 0x03
L2CAP_MODE_STREAM = 0x04
L2CAP_LISTEN_WITH_MODE = 0x0e
L2CAP_EV_CONNECTION_REQ = 0x80
L2CAP_EV_CONNECTED = 0x81
L2CAP_EV_DISCONNECTED = 0x82
Expand Down
41 changes: 41 additions & 0 deletions doc/btp_l2cap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,47 @@ Commands and responses:

In case of an error, the error response will be returned.

Opcode 0x0e - Listen with specified mdoe command

Controller Index: <controller id>
Command parameters: PSM (2 octets)
Transport (1 octet)
Mode (1 octet)
MTU (2 octets)
Key_Size (1 octet)
Response (2 octets)
Response parameters: <none>

Valid Transport parameter values:
0x00 = BR/EDR
0x01 = LE

Valid Mode parameter values:
0x00 = Basic
0x01 = Retransmission
0x02 = Flow Control
0x03 = Enhanced Retransmission
0x04 = Streaming

This command is used to register L2CAP PSM and listen for
incoming data.

The MTU parameter is used to specify initial MTU for channels.

Response parameter can be used to specify a response value used in
L2CAP Connection Response to send non-success responses like
Insufficient Authentication. If device bases its security requirements
for creating L2CAP connection on PSM, this value should be 0x00.

Valid Response values:
0x00 = Success
0x01 = Insufficient authentication
0x02 = Insufficient authorization
0x03 = Insufficient encryption key size
0x04 = Insufficient encryption

In case of an error, the error response will be returned.

Events:
Opcode 0x80 - Connection Request Event

Expand Down

0 comments on commit 496c286

Please sign in to comment.