<s> """<STR_LIT>""" <EOL> import socket , struct <EOL> from scapy . config import conf <EOL> from scapy . packet import * <EOL> from scapy . fields import * <EOL> from scapy . supersocket import SuperSocket <EOL> from scapy . data import MTU <EOL> class HCI_Hdr ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ ByteEnumField ( "<STR_LIT:type>" , <NUM_LIT:2> , { <NUM_LIT:1> : "<STR_LIT>" , <NUM_LIT:2> : "<STR_LIT>" , <NUM_LIT:3> : "<STR_LIT>" , <NUM_LIT:4> : "<STR_LIT>" , <NUM_LIT:5> : "<STR_LIT>" } ) , ] <EOL> def mysummary ( self ) : <EOL> return self . sprintf ( "<STR_LIT>" ) <EOL> class HCI_ACL_Hdr ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ ByteField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ByteField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortField ( "<STR_LIT>" , None ) , ] <EOL> def post_build ( self , p , pay ) : <EOL> p += pay <EOL> if self . len is None : <EOL> l = len ( p ) - <NUM_LIT:4> <EOL> p = p [ : <NUM_LIT:2> ] + bytes ( [ ( l & <NUM_LIT> ) , ( ( l >> <NUM_LIT:8> ) & <NUM_LIT> ) ] ) + p [ <NUM_LIT:4> : ] <EOL> return p <EOL> class L2CAP_Hdr ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT>" , None ) , <EOL> LEShortEnumField ( "<STR_LIT>" , <NUM_LIT:0> , { <NUM_LIT:1> : "<STR_LIT>" } ) , ] <EOL> def post_build ( self , p , pay ) : <EOL> p += pay <EOL> if self . len is None : <EOL> l = len ( p ) - <NUM_LIT:4> <EOL> p = p [ : <NUM_LIT:2> ] + bytes ( [ ( l & <NUM_LIT> ) , ( ( l >> <NUM_LIT:8> ) & <NUM_LIT> ) ] ) + p [ <NUM_LIT:4> : ] <EOL> return p <EOL> class L2CAP_CmdHdr ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ <EOL> ByteEnumField ( "<STR_LIT:code>" , <NUM_LIT:8> , { <NUM_LIT:1> : "<STR_LIT>" , <NUM_LIT:2> : "<STR_LIT>" , <NUM_LIT:3> : "<STR_LIT>" , <EOL> <NUM_LIT:4> : "<STR_LIT>" , <NUM_LIT:5> : "<STR_LIT>" , <NUM_LIT:6> : "<STR_LIT>" , <EOL> <NUM_LIT:7> : "<STR_LIT>" , <NUM_LIT:8> : "<STR_LIT>" , <NUM_LIT:9> : "<STR_LIT>" , <EOL> <NUM_LIT:10> : "<STR_LIT>" , <NUM_LIT:11> : "<STR_LIT>" } ) , <EOL> ByteField ( "<STR_LIT:id>" , <NUM_LIT:0> ) , <EOL> LEShortField ( "<STR_LIT>" , None ) ] <EOL> def post_build ( self , p , pay ) : <EOL> p += pay <EOL> if self . len is None : <EOL> l = len ( p ) - <NUM_LIT:4> <EOL> p = p [ : <NUM_LIT:2> ] + bytes ( [ ( l & <NUM_LIT> ) , ( ( l >> <NUM_LIT:8> ) & <NUM_LIT> ) ] ) + p [ <NUM_LIT:4> : ] <EOL> return p <EOL> def answers ( self , other ) : <EOL> if other . id == self . id : <EOL> if self . code == <NUM_LIT:1> : <EOL> return <NUM_LIT:1> <EOL> if other . code in [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:10> ] and self . code == other . code + <NUM_LIT:1> : <EOL> if other . code == <NUM_LIT:8> : <EOL> return <NUM_LIT:1> <EOL> return self . payload . answers ( other . payload ) <EOL> return <NUM_LIT:0> <EOL> class L2CAP_ConnReq ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortEnumField ( "<STR_LIT>" , <NUM_LIT:0> , { <NUM_LIT:1> : "<STR_LIT>" , <NUM_LIT:3> : "<STR_LIT>" , <NUM_LIT:5> : "<STR_LIT>" } ) , <EOL> LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ] <EOL> class L2CAP_ConnResp ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortEnumField ( "<STR_LIT:result>" , <NUM_LIT:0> , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> LEShortEnumField ( "<STR_LIT:status>" , <NUM_LIT:0> , [ "<STR_LIT:success>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ] <EOL> def answers ( self , other ) : <EOL> return self . scid == other . scid <EOL> class L2CAP_CmdRej ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ] <EOL> class L2CAP_ConfReq ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ] <EOL> class L2CAP_ConfResp ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortEnumField ( "<STR_LIT:result>" , <NUM_LIT:0> , [ "<STR_LIT:success>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ] <EOL> def answers ( self , other ) : <EOL> return self . scid == other . scid <EOL> class L2CAP_DisconnReq ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , ] <EOL> class L2CAP_DisconnResp ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> LEShortField ( "<STR_LIT>" , <NUM_LIT:0> ) , ] <EOL> def answers ( self , other ) : <EOL> return self . scid == other . scid <EOL> class L2CAP_InfoReq ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortEnumField ( "<STR_LIT:type>" , <NUM_LIT:0> , { <NUM_LIT:1> : "<STR_LIT>" , <NUM_LIT:2> : "<STR_LIT>" } ) , <EOL> StrField ( "<STR_LIT:data>" , "<STR_LIT>" ) <EOL> ] <EOL> class L2CAP_InfoResp ( Packet ) : <EOL> name = "<STR_LIT>" <EOL> fields_desc = [ LEShortField ( "<STR_LIT:type>" , <NUM_LIT:0> ) , <EOL> LEShortEnumField ( "<STR_LIT:result>" , <NUM_LIT:0> , [ "<STR_LIT:success>" , "<STR_LIT>" ] ) , <EOL> StrField ( "<STR_LIT:data>" , "<STR_LIT>" ) , ] <EOL> def answers ( self , other ) : <EOL> return self . type == other . type <EOL> bind_layers ( HCI_Hdr , HCI_ACL_Hdr , type = <NUM_LIT:2> ) <EOL> bind_layers ( HCI_Hdr , conf . raw_layer , ) <EOL> bind_layers ( HCI_ACL_Hdr , L2CAP_Hdr , ) <EOL> bind_layers ( L2CAP_Hdr , L2CAP_CmdHdr , cid = <NUM_LIT:1> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_CmdRej , code = <NUM_LIT:1> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_ConnReq , code = <NUM_LIT:2> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_ConnResp , code = <NUM_LIT:3> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_ConfReq , code = <NUM_LIT:4> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_ConfResp , code = <NUM_LIT:5> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_DisconnReq , code = <NUM_LIT:6> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_DisconnResp , code = <NUM_LIT:7> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_InfoReq , code = <NUM_LIT:10> ) <EOL> bind_layers ( L2CAP_CmdHdr , L2CAP_InfoResp , code = <NUM_LIT:11> ) <EOL> class BluetoothL2CAPSocket ( SuperSocket ) : <EOL> desc = "<STR_LIT>" <EOL> def __init__ ( self , peer ) : <EOL> s = socket . socket ( socket . AF_BLUETOOTH , socket . SOCK_RAW , <EOL> socket . BTPROTO_L2CAP ) <EOL> s . connect ( ( peer , <NUM_LIT:0> ) ) <EOL> self . ins = self . outs = s <EOL> def recv ( self , x = MTU ) : <EOL> return L2CAP_CmdHdr ( self . ins . recv ( x ) ) <EOL> class BluetoothHCISocket ( SuperSocket ) : <EOL> desc = "<STR_LIT>" <EOL> def __init__ ( self , iface = <NUM_LIT> , type = None ) : <EOL> s = socket . socket ( socket . AF_BLUETOOTH , socket . SOCK_RAW , socket . BTPROTO_HCI ) <EOL> s . setsockopt ( socket . SOL_HCI , socket . HCI_DATA_DIR , <NUM_LIT:1> ) <EOL> s . setsockopt ( socket . SOL_HCI , socket . HCI_TIME_STAMP , <NUM_LIT:1> ) <EOL> s . setsockopt ( socket . SOL_HCI , socket . HCI_FILTER , struct . pack ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) ) <EOL> s . bind ( ( iface , ) ) <EOL> self . ins = self . outs = s <EOL> def recv ( self , x ) : <EOL> return HCI_Hdr ( self . ins . recv ( x ) ) <EOL> @ conf . commands . register <EOL> def srbt ( peer , pkts , inter = <NUM_LIT:0.1> , * args , ** kargs ) : <EOL> """<STR_LIT>""" <EOL> s = conf . BTsocket ( peer = peer ) <EOL> a , b = sndrcv ( s , pkts , inter = inter , * args , ** kargs ) <EOL> s . close ( ) <EOL> return a , b <EOL> @ conf . commands . register <EOL> def srbt1 ( peer , pkts , * args , ** kargs ) : <EOL> """<STR_LIT>""" <EOL> a , b = srbt ( peer , pkts , * args , ** kargs ) <EOL> if len ( a ) > <NUM_LIT:0> : <EOL> return a [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> conf . BTsocket = BluetoothL2CAPSocket </s>
