def gap_conn_param_update(bd_addr, bd_addr_type, conn_itvl_min, conn_itvl_max, conn_latency, supervision_timeout): logging.debug("%s %r %r", gap_conn_param_update.__name__, bd_addr, bd_addr_type) iutctl = get_iut() gap_wait_for_connection() data_ba = bytearray() bd_addr_ba = addr2btp_ba(pts_addr_get(bd_addr)) data_ba.extend(chr(pts_addr_type_get(bd_addr_type)).encode('utf-8')) data_ba.extend(bd_addr_ba) conn_itvl_min_ba = struct.pack('H', conn_itvl_min) conn_itvl_max_ba = struct.pack('H', conn_itvl_max) conn_latency_ba = struct.pack('H', conn_latency) supervision_timeout_ba = struct.pack('H', supervision_timeout) data_ba.extend(conn_itvl_min_ba) data_ba.extend(conn_itvl_max_ba) data_ba.extend(conn_latency_ba) data_ba.extend(supervision_timeout_ba) iutctl.btp_socket.send(*GAP['conn_param_update'], data=data_ba) # Expected result gap_command_rsp_succ()
def l2cap_conn(bd_addr, bd_addr_type, psm, mtu=0, num=1, ecfc=0, hold_credit=0): logging.debug("%s %r %r %r", l2cap_conn.__name__, bd_addr, bd_addr_type, psm) iutctl = get_iut() gap_wait_for_connection() if isinstance(psm, str): psm = int(psm, 16) bd_addr = pts_addr_get(bd_addr) bd_addr_type = pts_addr_type_get(bd_addr_type) bd_addr_ba = addr2btp_ba(bd_addr) data_ba = bytearray(chr(bd_addr_type).encode('utf-8')) data_ba.extend(bd_addr_ba) data_ba.extend(struct.pack('H', psm)) data_ba.extend(struct.pack('H', mtu)) data_ba.extend(struct.pack('B', num)) opts = 0 if ecfc: opts |= defs.L2CAP_CONNECT_OPT_ECFC if hold_credit: opts |= defs.L2CAP_CONNECT_OPT_HOLD_CREDIT data_ba.extend(struct.pack('B', opts)) iutctl.btp_socket.send(*L2CAP['connect'], data=data_ba) chan_ids = l2cap_conn_rsp() logging.debug("id %r", chan_ids)
def check_discov_results(addr_type=None, addr=None, discovered=True, eir=None): addr = pts_addr_get(addr).encode('utf-8') addr_type = pts_addr_type_get(addr_type) logging.debug("%s %r %r %r %r", check_discov_results.__name__, addr_type, addr, discovered, eir) found = False stack = get_stack() devices = stack.gap.found_devices.data for device in devices: logging.debug("matching %r", device) if addr_type != device.addr_type: continue if addr != device.addr: continue if eir and eir != device.eir: continue found = True break if discovered == found: return True return False
def set_filter_accept_list(address_list=None): """ Send tuples (address, address_type) to IUT and save them to the filter accept list. If address_list=None PTS's (address,type) will be sent. Arguments: address_list -- addrs and their types as tuples: address_list = [('DB:F5:72:56:C9:EF', 0), ('DB:F5:72:56:C9:EF', 0)] """ logging.debug("%s %s", set_filter_accept_list.__name__, address_list) iutctl = get_iut() data_ba = bytearray() if not address_list: address_list = [(pts_addr_get(None), pts_addr_type_get(None))] addr_cnt_ba = chr(len(address_list)).encode('utf-8') data_ba.extend(addr_cnt_ba) for addr, type in address_list: bd_addr_ba = addr2btp_ba(addr) bd_addr_type_ba = chr(type).encode('utf-8') data_ba.extend(bd_addr_type_ba) data_ba.extend(bd_addr_ba) iutctl.btp_socket.send(*GAP['set_filter_accept_list'], data=data_ba) gap_command_rsp_succ()
def gap_unpair(bd_addr=None, bd_addr_type=None): logging.debug("%s %r %r", gap_unpair.__name__, bd_addr, bd_addr_type) iutctl = get_iut() data_ba = bytearray() bd_addr_ba = addr2btp_ba(pts_addr_get(bd_addr)) data_ba.extend(chr(pts_addr_type_get(bd_addr_type)).encode('utf-8')) data_ba.extend(bd_addr_ba) iutctl.btp_socket.send(*GAP['unpair'], data=data_ba) # Expected result gap_command_rsp_succ(defs.GAP_UNPAIR)
def l2cap_disconn_eatt_chans(bd_addr, bd_addr_type, channel_count): logging.debug("%s %r", l2cap_disconn_eatt_chans.__name__, channel_count) iutctl = get_iut() bd_addr = pts_addr_get(bd_addr) bd_addr_type = pts_addr_type_get(bd_addr_type) bd_addr_ba = addr2btp_ba(bd_addr) data_ba = bytearray(chr(bd_addr_type).encode('utf-8')) data_ba.extend(bd_addr_ba) data_ba.extend(bytearray(chr(channel_count).encode('utf-8'))) iutctl.btp_socket.send(*L2CAP['disconnect_eatt_chans'], data=data_ba) l2cap_command_rsp_succ(defs.L2CAP_DISCONNECT_EATT_CHANS)
def gap_conn(bd_addr=None, bd_addr_type=None, own_addr_type=OwnAddrType.le_identity_address): logging.debug("%s %r %r", gap_conn.__name__, bd_addr, bd_addr_type) iutctl = get_iut() data_ba = bytearray() bd_addr_ba = addr2btp_ba(pts_addr_get(bd_addr)) data_ba.extend(chr(pts_addr_type_get(bd_addr_type)).encode('utf-8')) data_ba.extend(bd_addr_ba) data_ba.extend(chr(own_addr_type).encode('utf-8')) iutctl.btp_socket.send(*GAP['conn'], data=data_ba) gap_command_rsp_succ()
def gap_disconn(bd_addr=None, bd_addr_type=None): logging.debug("%s %r %r", gap_disconn.__name__, bd_addr, bd_addr_type) iutctl = get_iut() stack = get_stack() if not stack.gap.is_connected(): return data_ba = bytearray() bd_addr_ba = addr2btp_ba(pts_addr_get(bd_addr)) data_ba.extend(chr(pts_addr_type_get(bd_addr_type)).encode('utf-8')) data_ba.extend(bd_addr_ba) iutctl.btp_socket.send(*GAP['disconn'], data=data_ba) gap_command_rsp_succ()
def l2cap_reconfigure(bd_addr, bd_addr_type, mtu, channels): logging.debug("%s %r %r %r %r", l2cap_reconfigure.__name__, bd_addr, bd_addr_type, mtu, channels) iutctl = get_iut() bd_addr = pts_addr_get(bd_addr) bd_addr_type = pts_addr_type_get(bd_addr_type) bd_addr_ba = addr2btp_ba(bd_addr) data_ba = bytearray(chr(bd_addr_type).encode('utf-8')) data_ba.extend(bd_addr_ba) data_ba.extend(struct.pack('H', mtu)) data_ba.extend(struct.pack('B', len(channels))) for chan in channels: data_ba.extend(struct.pack('B', chan)) iutctl.btp_socket.send(*L2CAP['reconfigure'], data=data_ba) l2cap_command_rsp_succ(defs.L2CAP_RECONFIGURE)
def gap_conn_param_update_ev_(gap, data, data_len): logging.debug("%s", gap_conn_param_update_ev_.__name__) logging.debug("received %r", data) fmt = '<B6sHHH' if len(data) != struct.calcsize(fmt): raise BTPError("Invalid data length") _addr_t, _addr, _itvl, _latency, _timeout = struct.unpack_from(fmt, data) # Convert addresses to lower case _addr = binascii.hexlify(_addr[::-1]).lower() if _addr_t != pts_addr_type_get() or _addr.decode( 'utf-8') != pts_addr_get(): raise BTPError("Received data mismatch") logging.debug("received %r", (_addr_t, _addr, _itvl, _latency, _timeout)) gap.set_conn_params(ConnParams(_itvl, _latency, _timeout))
def gap_identity_resolved_ev_(gap, data, data_len): logging.debug("%s", gap_identity_resolved_ev_.__name__) logging.debug("received %r", data) fmt = '<B6sB6s' if len(data) != struct.calcsize(fmt): raise BTPError("Invalid data length") _addr_t, _addr, _id_addr_t, _id_addr = struct.unpack_from(fmt, data) # Convert addresses to lower case _addr = binascii.hexlify(_addr[::-1]).lower() _id_addr = binascii.hexlify(_id_addr[::-1]).lower() if _addr_t != pts_addr_type_get() or _addr.decode( 'utf-8') != pts_addr_get(): raise BTPError("Received data mismatch") # Update RPA with Identity Address set_pts_addr(_id_addr, _id_addr_t)
def l2cap_conn(bd_addr, bd_addr_type, psm, mtu=0, num=1): logging.debug("%s %r %r %r", l2cap_conn.__name__, bd_addr, bd_addr_type, psm) iutctl = get_iut() gap_wait_for_connection() if isinstance(psm, str): psm = int(psm, 16) bd_addr = pts_addr_get(bd_addr) bd_addr_type = pts_addr_type_get(bd_addr_type) bd_addr_ba = addr2btp_ba(bd_addr) data_ba = bytearray(chr(bd_addr_type).encode('utf-8')) data_ba.extend(bd_addr_ba) data_ba.extend(struct.pack('H', psm)) data_ba.extend(struct.pack('H', mtu)) data_ba.extend(struct.pack('B', num)) iutctl.btp_socket.send(*L2CAP['connect'], data=data_ba) chan_ids = l2cap_conn_rsp() logging.debug("id %r", chan_ids)
def gap_rpa_conn(description, own_addr_type=OwnAddrType.le_identity_address): """Initiate connection with PTS using RPA address provided in MMI description. Function returns True. Arguments: description -- description provided in PTS MMI. """ logging.debug("%s %s", gap_conn.__name__, description) iutctl = get_iut() bd_addr = re.search("[a-fA-F0-9]{12}", description).group(0) bd_addr_type = Addr.le_random data_ba = bytearray() bd_addr_ba = addr2btp_ba(pts_addr_get(bd_addr)) data_ba.extend(chr(pts_addr_type_get(bd_addr_type)).encode('utf-8')) data_ba.extend(bd_addr_ba) data_ba.extend(chr(own_addr_type).encode('utf-8')) iutctl.btp_socket.send(*GAP['conn'], data=data_ba) gap_command_rsp_succ() return True