<s> import os <EOL> import sys <EOL> import struct <EOL> import bluetooth . _bluetooth as _bt <EOL> def read_local_bdaddr ( hci_sock ) : <EOL> old_filter = hci_sock . getsockopt ( _bt . SOL_HCI , _bt . HCI_FILTER , <NUM_LIT> ) <EOL> flt = _bt . hci_filter_new ( ) <EOL> opcode = _bt . cmd_opcode_pack ( _bt . OGF_INFO_PARAM , <EOL> _bt . OCF_READ_BD_ADDR ) <EOL> _bt . hci_filter_set_ptype ( flt , _bt . HCI_EVENT_PKT ) <EOL> _bt . hci_filter_set_event ( flt , _bt . EVT_CMD_COMPLETE ) ; <EOL> _bt . hci_filter_set_opcode ( flt , opcode ) <EOL> hci_sock . setsockopt ( _bt . SOL_HCI , _bt . HCI_FILTER , flt ) <EOL> _bt . hci_send_cmd ( hci_sock , _bt . OGF_INFO_PARAM , _bt . OCF_READ_BD_ADDR ) <EOL> pkt = hci_sock . recv ( <NUM_LIT:255> ) <EOL> status , raw_bdaddr = struct . unpack ( "<STR_LIT>" , pkt ) <EOL> assert status == <NUM_LIT:0> <EOL> t = [ "<STR_LIT>" % ord ( b ) for b in raw_bdaddr ] <EOL> t . reverse ( ) <EOL> bdaddr = "<STR_LIT::>" . join ( t ) <EOL> hci_sock . setsockopt ( _bt . SOL_HCI , _bt . HCI_FILTER , old_filter ) <EOL> return bdaddr <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> dev_id = <NUM_LIT:0> <EOL> hci_sock = _bt . hci_open_dev ( dev_id ) <EOL> bdaddr = read_local_bdaddr ( hci_sock ) <EOL> print bdaddr </s>
