def config_option_ertm(mtu=642, fcs=None, max_transmit=10, mps=1010, tx_window_size=10, monitor_time_out=2000, retransmission_time_out=1000): result = [] mtu_opt = l2cap_packets.MtuConfigurationOption() mtu_opt.mtu = mtu result.append(mtu_opt) if fcs is not None: fcs_opt = l2cap_packets.FrameCheckSequenceOption() fcs_opt.fcs_type = fcs result.append(fcs_opt) rfc_opt = l2cap_packets.RetransmissionAndFlowControlConfigurationOption( ) rfc_opt.mode = l2cap_packets.RetransmissionAndFlowControlModeOption.ENHANCED_RETRANSMISSION rfc_opt.tx_window_size = tx_window_size rfc_opt.max_transmit = max_transmit rfc_opt.retransmission_time_out = retransmission_time_out rfc_opt.monitor_time_out = monitor_time_out rfc_opt.maximum_pdu_size = mps result.append(rfc_opt) return result
def config_option_basic_explicit(mtu=642): mtu_opt = l2cap_packets.MtuConfigurationOption() mtu_opt.mtu = mtu rfc_opt = l2cap_packets.RetransmissionAndFlowControlConfigurationOption( ) rfc_opt.mode = l2cap_packets.RetransmissionAndFlowControlModeOption.L2CAP_BASIC return [mtu_opt, rfc_opt]
def test_l2cap_config_options(self): mtu_opt = l2cap_packets.MtuConfigurationOption() mtu_opt.mtu = 123 fcs_opt = l2cap_packets.FrameCheckSequenceOption() fcs_opt.fcs_type = l2cap_packets.FcsType.DEFAULT request = l2cap_packets.ConfigurationRequestBuilder( 0x1d, # Command ID 0xc1d, # Channel ID l2cap_packets.Continuation.END, [mtu_opt, fcs_opt]) request_b_frame = l2cap_packets.BasicFrameBuilder(0x01, request) handle = 123 wrapped = hci_packets.AclPacketBuilder( handle, hci_packets.PacketBoundaryFlag.FIRST_NON_AUTOMATICALLY_FLUSHABLE, hci_packets.BroadcastFlag.POINT_TO_POINT, request_b_frame) # Size is ACL (4) + L2CAP (4) + Configure (8) + MTU (4) + FCS (3) asserts.assert_true( len(wrapped.Serialize()) == 23, "Packet serialized incorrectly")
def config_option_mtu_explicit(mtu=642): mtu_opt = l2cap_packets.MtuConfigurationOption() mtu_opt.mtu = mtu return [mtu_opt]