Skip to content
Snippets Groups Projects
Commit e1328b42 authored by Younus Salman's avatar Younus Salman
Browse files

beacon_1.py has wifi config now

parent 6ea70db4
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ from drippy.util import astm_float_to_int_hex, get_timestamp, astm_time ...@@ -22,7 +22,7 @@ from drippy.util import astm_float_to_int_hex, get_timestamp, astm_time
from drippy.host_identity import HostIdentity from drippy.host_identity import HostIdentity
from drippy.cSHAKE import cSHAKE128 from drippy.cSHAKE import cSHAKE128
from wifi_beacon import beacon_wifi
# File with flight_id that will be incremented and used if no other # File with flight_id that will be incremented and used if no other
...@@ -115,28 +115,32 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id, HostID: Ho ...@@ -115,28 +115,32 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id, HostID: Ho
) )
payload = HostID.generate_self_attestation_Wrapper(hash_location, get_timestamp(exp_date)) payload = HostID.generate_self_attestation_Wrapper(hash_location, get_timestamp(exp_date))
# Set (Extended) Advertising command
if is_bt5: if is_wifi:
""" beacon_wifi("{hash_location}{payload}".format(hash_location=hash_location,payload=payload))
OGF: 0x08 (LE controller commands)
OCF: 0x0037 (LE Set Extended Advertising Data command)
Advertising handle: 0x00 (Advertising set number)
Operation: 0x03 (Complete extended advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x10 {hash_location}{payload}".format(hash_location=hash_location,payload=payload), shell=True)
else: else:
""" # Set (Extended) Advertising command
OGF: 0x08 (LE controller commands) if is_bt5:
OCF: 0x0008 (LE Set Advertising Data command) """
Advertising_Data_Length: 0x1f OGF: 0x08 (LE controller commands)
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload OCF: 0x0037 (LE Set Extended Advertising Data command)
""" Advertising handle: 0x00 (Advertising set number)
subprocess.run( Operation: 0x03 (Complete extended advertising data)
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 10 {hash_location}{payload}".format(hash_location=hash_location, payload=payload), shell=True) Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x10 {hash_location}{payload}".format(hash_location=hash_location,payload=payload), shell=True)
else:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 10 {hash_location}{payload}".format(hash_location=hash_location, payload=payload), shell=True)
def manifest_broadcast(HostID: HostIdentity, flight_id, exp_date, prev_loc = "" ): ## Manifest broadcast can contain max 11 hashes (at 8-bytes each). For now we are sending one message. def manifest_broadcast(HostID: HostIdentity, flight_id, exp_date, prev_loc = "" ): ## Manifest broadcast can contain max 11 hashes (at 8-bytes each). For now we are sending one message.
...@@ -180,60 +184,66 @@ def basic_id_update(hhit): ...@@ -180,60 +184,66 @@ def basic_id_update(hhit):
print("basic_id_update") print("basic_id_update")
# Set (Extended) Advertising Command # Set (Extended) Advertising Command
if is_bt5: if is_wifi:
""" beacon_wifi("{} 0x00 0x00 0x00 0x00 0x00 0x00 0x00".format('0x01', hhit))
OGF: 0x08 (LE controller commands)
OCF: 0x0037 (LE Set Extended Advertising Data command)
Advertising handle: 0x00 (Advertising set number)
Operation: 0x03 (Complete extended advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + hhit
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x00 0x42 {} 0x00 0x00 0x00 0x00 0x00 0x00 0x00".format('0x01', hhit), shell=True)
else: else:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 00 42 + hhit
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 00 42 {} 00 00 00 00 00 00 00".format('0x01', hhit), shell=True)
time.sleep(0.5)
def auth_update(auth_pages, msg_number):
print("auth_update")
for page in auth_pages:
msg = separate_bytes(hexlify(page).decode("utf-8"))
# Set (Extended) Advertising Command
if is_bt5: if is_bt5:
""" """
OGF: 0x08 (LE controller commands) OGF: 0x08 (LE controller commands)
OCF: 0x0037 (LE Set Extended Advertising Data command) OCF: 0x0037 (LE Set Extended Advertising Data command)
Advertising handle: 0x00 (Advertising set number) Advertising handle: 0x00 (Advertising set number)
Operation: 0x01 / 0x02 (First and last part of advertising data) Operation: 0x03 (Complete extended advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data) Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 20 + msg Advertising_Data: 1e 16 fa ff 0d 00 10 + hhit
""" """
if msg_number == 1: subprocess.run(
subprocess.run( "hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x00 0x42 {} 0x00 0x00 0x00 0x00 0x00 0x00 0x00".format('0x01', hhit), shell=True)
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x01 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d {} 0x20 {}".format("00", msg), shell=True)
elif msg_number == 2:
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x02 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d {} 0x20 {}".format("00", msg), shell=True)
else: else:
""" """
OGF: 0x08 (LE controller commands) OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command) OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 20 + msg Advertising_Data: 1e 16 fa ff 0d 00 00 42 + hhit
""" """
subprocess.run( subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d {} 20 {}".format("00", msg), shell=True) "hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 00 42 {} 00 00 00 00 00 00 00".format('0x01', hhit), shell=True)
time.sleep(0.5)
def auth_update(auth_pages, msg_number):
print("auth_update")
for page in auth_pages:
msg = separate_bytes(hexlify(page).decode("utf-8"))
# Set (Extended) Advertising Command
if is_wifi:
beacon_wifi(msg)
else:
if is_bt5:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0037 (LE Set Extended Advertising Data command)
Advertising handle: 0x00 (Advertising set number)
Operation: 0x01 / 0x02 (First and last part of advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 20 + msg
"""
if msg_number == 1:
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x01 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d {} 0x20 {}".format("00", msg), shell=True)
elif msg_number == 2:
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x02 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d {} 0x20 {}".format("00", msg), shell=True)
else:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 20 + msg
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d {} 20 {}".format("00", msg), shell=True)
time.sleep(0.2) time.sleep(0.2)
...@@ -254,6 +264,9 @@ def main(): ...@@ -254,6 +264,9 @@ def main():
global g_lat global g_lat
global g_lon global g_lon
global is_bt5 global is_bt5
global is_wifi
parser = argparse.ArgumentParser(description=DESCRIPTION) parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument( parser.add_argument(
"-f", "--file", "-f", "--file",
...@@ -284,6 +297,12 @@ def main(): ...@@ -284,6 +297,12 @@ def main():
type=int, type=int,
help="Specify the bluetooth version, 4 or 5 (Default: 4)." help="Specify the bluetooth version, 4 or 5 (Default: 4)."
) )
parser.add_argument(
"--wifi",
dest="activate_wifi",
default= False,
action= "store_true",
)
parser.add_argument( parser.add_argument(
"--gps", "--gps",
help="Turn on gps updates", help="Turn on gps updates",
...@@ -319,7 +338,7 @@ def main(): ...@@ -319,7 +338,7 @@ def main():
iroha_priv_key_file = args.iroha_priv_key_file iroha_priv_key_file = args.iroha_priv_key_file
is_bt5 = True if args.bluetooth_version == 5 else False is_bt5 = True if args.bluetooth_version == 5 else False
is_wifi= args.activate_wifi
exp_date = datetime.strptime(args.exp_date, "%Y-%m-%dT%H:%M") exp_date = datetime.strptime(args.exp_date, "%Y-%m-%dT%H:%M")
if (exp_date - datetime.utcnow()).total_seconds() <= 0: if (exp_date - datetime.utcnow()).total_seconds() <= 0:
print("Expiration date cannot come before current date.") print("Expiration date cannot come before current date.")
...@@ -373,63 +392,64 @@ def main(): ...@@ -373,63 +392,64 @@ def main():
subprocess.run("hcitool -i hci0 cmd 0x03 0x0003", shell=True) subprocess.run("hcitool -i hci0 cmd 0x03 0x0003", shell=True)
# Set (Extended) Advertising Parameters # Set (Extended) Advertising Parameters
if is_bt5: if not is_wifi:
""" if is_bt5:
OGF: 0x08 (LE controller commands) """
OCF: 0x0036 (LE Set Extended Advertising Parameters command) OGF: 0x08 (LE controller commands)
Advertising handle: 0x00 (Advertising set number) OCF: 0x0036 (LE Set Extended Advertising Parameters command)
Advertising_Event_Properties: 0x0000 (Non-connectable, non-scannable undirected and not legacy PDU) Advertising handle: 0x00 (Advertising set number)
Primary_Advertising_Interval_Min: 0xa00000 (100 ms) Advertising_Event_Properties: 0x0000 (Non-connectable, non-scannable undirected and not legacy PDU)
Primary_Advertising_Interval_Max: 0xa00000 (100 ms) Primary_Advertising_Interval_Min: 0xa00000 (100 ms)
Primary_Advertising_Channel_Map: 0x07 (All three channels enabled) Primary_Advertising_Interval_Max: 0xa00000 (100 ms)
Own_Address_Type: 0x00 (Public device address) Primary_Advertising_Channel_Map: 0x07 (All three channels enabled)
Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address) Own_Address_Type: 0x00 (Public device address)
Peer_Address: 0x000000000000 Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address)
Advertising_Filter_Policy: 0x02 (Process scan requests: all devices, Connection requests: only Filter Accept List) Peer_Address: 0x000000000000
Advertising_TX_Power: 0x7f (Host has no preference) Advertising_Filter_Policy: 0x02 (Process scan requests: all devices, Connection requests: only Filter Accept List)
Primary_Advertising_PHY: 0x03 (Primary advertisement PHY is LE Coded) Advertising_TX_Power: 0x7f (Host has no preference)
Secondary_Advertising_Max_Skip: 0x00 (AUX_ADV_IND shall be sent prior to the next advertising event) Primary_Advertising_PHY: 0x03 (Primary advertisement PHY is LE Coded)
Secondary_Advertising_PHY: 0x03 (Secondary advertisement PHY is LE Coded) Secondary_Advertising_Max_Skip: 0x00 (AUX_ADV_IND shall be sent prior to the next advertising event)
Advertising_SID: 0x00 (Value of the Advertising SID subfield in the ADI field of the PDU) Secondary_Advertising_PHY: 0x03 (Secondary advertisement PHY is LE Coded)
Scan_Request_Notification_Enable: 0x00 (Scan request notifications disabled) Advertising_SID: 0x00 (Value of the Advertising SID subfield in the ADI field of the PDU)
""" Scan_Request_Notification_Enable: 0x00 (Scan request notifications disabled)
subprocess.run( """
"hcitool -i hci0 cmd 0x08 0x0036 0x00 0x00 0x00 0xa0 0x00 0x00 0xa0 0x00 0x00 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x02 0x7f 0x03 0x00 0x03 0x00 0x00", shell=True) subprocess.run(
else: "hcitool -i hci0 cmd 0x08 0x0036 0x00 0x00 0x00 0xa0 0x00 0x00 0xa0 0x00 0x00 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x02 0x7f 0x03 0x00 0x03 0x00 0x00", shell=True)
""" else:
OGF: 0x08 (LE controller commands) """
OCF: 0x0006 (LE Set Advertising Parameters command) OGF: 0x08 (LE controller commands)
Advertising_Interval_Min: 0xa000 (100 ms) OCF: 0x0006 (LE Set Advertising Parameters command)
Advertising_Interval_Max: 0xa000 (100 ms) Advertising_Interval_Min: 0xa000 (100 ms)
Advertising_Type: 0x03 (Non connectable undirected advertising (ADV_NONCONN_IND)) Advertising_Interval_Max: 0xa000 (100 ms)
Own_Address_Type: 0x00 (Public device address) Advertising_Type: 0x03 (Non connectable undirected advertising (ADV_NONCONN_IND))
Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address) Own_Address_Type: 0x00 (Public device address)
Peer_Address: 0x000000000000 Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address)
Advertising_Channel_Map: 0x07 (All three channels enabled) Peer_Address: 0x000000000000
Advertising_Filter_Policy: 0x02 (Process scan requests: all devices, Connection requests: only Filter Accept List) Advertising_Channel_Map: 0x07 (All three channels enabled)
""" Advertising_Filter_Policy: 0x02 (Process scan requests: all devices, Connection requests: only Filter Accept List)
subprocess.run( """
"hcitool -i hci0 cmd 0x08 0x0006 a0 00 a0 00 03 00 00 00 00 00 00 00 00 07 02", shell=True) subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0006 a0 00 a0 00 03 00 00 00 00 00 00 00 00 07 02", shell=True)
# Enable (Extended) Bluetooth Advertisement # Enable (Extended) Bluetooth Advertisement
if is_bt5: if is_bt5:
""" """
OGF: 0x08 (LE controller commands) OGF: 0x08 (LE controller commands)
OCF: 0x0039 (LE Set Extended Advertising Enable command) OCF: 0x0039 (LE Set Extended Advertising Enable command)
Enable: 0x01 (True) Enable: 0x01 (True)
Num_Sets: 0x01 (Number of advertising sets to enable) Num_Sets: 0x01 (Number of advertising sets to enable)
Advertising_Handle[i]: 0x00 (Advertising set's handles) Advertising_Handle[i]: 0x00 (Advertising set's handles)
Duration[i]: 0x0000 (Advertise until the Host disables it) Duration[i]: 0x0000 (Advertise until the Host disables it)
Max_Extended_Advertising_Events[i]: 0x00 (No maximum) Max_Extended_Advertising_Events[i]: 0x00 (No maximum)
""" """
subprocess.run("hcitool -i hci0 cmd 0x08 0x0039 0x01 0x01 0x00 0x00 0x00 0x00", shell=True) subprocess.run("hcitool -i hci0 cmd 0x08 0x0039 0x01 0x01 0x00 0x00 0x00 0x00", shell=True)
else: else:
""" """
OGF: 0x08 (LE controller commands) OGF: 0x08 (LE controller commands)
OCF: 0x000a (LE Set Advertising Enable command) OCF: 0x000a (LE Set Advertising Enable command)
Enable: 0x01 (True) Enable: 0x01 (True)
""" """
subprocess.run("hcitool -i hci0 cmd 0x08 0x000a 01", shell=True) subprocess.run("hcitool -i hci0 cmd 0x08 0x000a 01", shell=True)
gpsd = None gpsd = None
if not args.run_scenario and args.gps: if not args.run_scenario and args.gps:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment