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

wifi code is done but needs testing

parent 3ac41e53
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,9 @@ from drippy.gps_poll import GpsPoller ...@@ -21,6 +21,9 @@ from drippy.gps_poll import GpsPoller
from drippy.util import astm_float_to_int_hex, get_timestamp, astm_time 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 wifi_beacon import beacon_wifi
from uuid import getnode as get_mac
# 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
# flight_id is specified. # flight_id is specified.
FLIGHT_ID_FILE = os.path.join(FILE_DIR, "default_flight_id.txt") FLIGHT_ID_FILE = os.path.join(FILE_DIR, "default_flight_id.txt")
...@@ -105,88 +108,100 @@ def location_update(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id): ...@@ -105,88 +108,100 @@ def location_update(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id):
iroha.set_account_details, "location", iroha_msg iroha.set_account_details, "location", iroha_msg
) )
# Set (Extended) Advertising command if is_wifi:
if is_bt5: beacon_wifi(mac_arr, "0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x10 {payload}".format(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 {payload}".format(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 {payload}".format(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 {payload}".format(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 {payload}".format(payload=payload), shell=True)
def basic_id_update(hhit): def basic_id_update(hhit):
# ASTM F3-411 Basic ID message 0x0 with HHIT. # ASTM F3-411 Basic ID message 0x0 with 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(mac_arr, "0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x00 0x42 {} 0x00 0x00 0x00 0x00 0x00 0x00 0x00".format(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(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(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(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(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"))
if is_wifi:
if msg_number == 1:
beacon_wifi(mac_arr, "0x08 0x0037 0x00 0x01 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d {} 0x20 {}".format("00", msg))
elif msg_number == 2:
beacon_wifi(mac_arr, "0x08 0x0037 0x00 0x02 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d {} 0x20 {}".format("00", msg))
else:
# Set (Extended) Advertising Command
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)
...@@ -207,6 +222,10 @@ def main(): ...@@ -207,6 +222,10 @@ def main():
global g_lat global g_lat
global g_lon global g_lon
global is_bt5 global is_bt5
global is_wifi
global mac_arr
parser = argparse.ArgumentParser(description=DESCRIPTION) parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument( parser.add_argument(
"-f", "--file", "-f", "--file",
...@@ -229,6 +248,13 @@ def main(): ...@@ -229,6 +248,13 @@ 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"
type= bool
)
parser.add_argument( parser.add_argument(
"--gps", "--gps",
help="Turn on gps updates", help="Turn on gps updates",
...@@ -258,6 +284,7 @@ def main(): ...@@ -258,6 +284,7 @@ def main():
hi_file = args.host_identity_file hi_file = args.host_identity_file
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:
...@@ -296,67 +323,75 @@ def main(): ...@@ -296,67 +323,75 @@ def main():
auth_pages = get_auth_pages(attest) auth_pages = get_auth_pages(attest)
# Reset bt mac = hex(get_mac()) # fetches device mac address
subprocess.run("hcitool -i hci0 cmd 0x03 0x0003", shell=True) mac_arr = list(bytearray.fromhex(mac[2:])) # converts it into int
# Set (Extended) Advertising Parameters if is_wifi:
if is_bt5: beacon_wifi(mac_arr, "0x03 0x0003")
""" beacon_wifi(mac_arr, "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")
OGF: 0x08 (LE controller commands) beacon_wifi(mac_arr, "0x08 0x0039 0x01 0x01 0x00 0x00 0x00 0x00")
OCF: 0x0036 (LE Set Extended Advertising Parameters command)
Advertising handle: 0x00 (Advertising set number)
Advertising_Event_Properties: 0x0000 (Non-connectable, non-scannable undirected and not legacy PDU)
Primary_Advertising_Interval_Min: 0xa00000 (100 ms)
Primary_Advertising_Interval_Max: 0xa00000 (100 ms)
Primary_Advertising_Channel_Map: 0x07 (All three channels enabled)
Own_Address_Type: 0x00 (Public device address)
Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address)
Peer_Address: 0x000000000000
Advertising_Filter_Policy: 0x02 (Process scan requests: all devices, Connection requests: only Filter Accept List)
Advertising_TX_Power: 0x7f (Host has no preference)
Primary_Advertising_PHY: 0x03 (Primary advertisement PHY is LE Coded)
Secondary_Advertising_Max_Skip: 0x00 (AUX_ADV_IND shall be sent prior to the next advertising event)
Secondary_Advertising_PHY: 0x03 (Secondary advertisement PHY is LE Coded)
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)
else:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0006 (LE Set Advertising Parameters command)
Advertising_Interval_Min: 0xa000 (100 ms)
Advertising_Interval_Max: 0xa000 (100 ms)
Advertising_Type: 0x03 (Non connectable undirected advertising (ADV_NONCONN_IND))
Own_Address_Type: 0x00 (Public device address)
Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address)
Peer_Address: 0x000000000000
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)
# Enable (Extended) Bluetooth Advertisement
if is_bt5:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0039 (LE Set Extended Advertising Enable command)
Enable: 0x01 (True)
Num_Sets: 0x01 (Number of advertising sets to enable)
Advertising_Handle[i]: 0x00 (Advertising set's handles)
Duration[i]: 0x0000 (Advertise until the Host disables it)
Max_Extended_Advertising_Events[i]: 0x00 (No maximum)
"""
subprocess.run("hcitool -i hci0 cmd 0x08 0x0039 0x01 0x01 0x00 0x00 0x00 0x00", shell=True)
else: else:
""" # Reset bt
OGF: 0x08 (LE controller commands) subprocess.run("hcitool -i hci0 cmd 0x03 0x0003", shell=True)
OCF: 0x000a (LE Set Advertising Enable command)
Enable: 0x01 (True) # Set (Extended) Advertising Parameters
""" if is_bt5:
subprocess.run("hcitool -i hci0 cmd 0x08 0x000a 01", shell=True) """
OGF: 0x08 (LE controller commands)
OCF: 0x0036 (LE Set Extended Advertising Parameters command)
Advertising handle: 0x00 (Advertising set number)
Advertising_Event_Properties: 0x0000 (Non-connectable, non-scannable undirected and not legacy PDU)
Primary_Advertising_Interval_Min: 0xa00000 (100 ms)
Primary_Advertising_Interval_Max: 0xa00000 (100 ms)
Primary_Advertising_Channel_Map: 0x07 (All three channels enabled)
Own_Address_Type: 0x00 (Public device address)
Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address)
Peer_Address: 0x000000000000
Advertising_Filter_Policy: 0x02 (Process scan requests: all devices, Connection requests: only Filter Accept List)
Advertising_TX_Power: 0x7f (Host has no preference)
Primary_Advertising_PHY: 0x03 (Primary advertisement PHY is LE Coded)
Secondary_Advertising_Max_Skip: 0x00 (AUX_ADV_IND shall be sent prior to the next advertising event)
Secondary_Advertising_PHY: 0x03 (Secondary advertisement PHY is LE Coded)
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)
else:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0006 (LE Set Advertising Parameters command)
Advertising_Interval_Min: 0xa000 (100 ms)
Advertising_Interval_Max: 0xa000 (100 ms)
Advertising_Type: 0x03 (Non connectable undirected advertising (ADV_NONCONN_IND))
Own_Address_Type: 0x00 (Public device address)
Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address)
Peer_Address: 0x000000000000
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)
# Enable (Extended) Bluetooth Advertisement
if is_bt5:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0039 (LE Set Extended Advertising Enable command)
Enable: 0x01 (True)
Num_Sets: 0x01 (Number of advertising sets to enable)
Advertising_Handle[i]: 0x00 (Advertising set's handles)
Duration[i]: 0x0000 (Advertise until the Host disables it)
Max_Extended_Advertising_Events[i]: 0x00 (No maximum)
"""
subprocess.run("hcitool -i hci0 cmd 0x08 0x0039 0x01 0x01 0x00 0x00 0x00 0x00", shell=True)
else:
"""
OGF: 0x08 (LE controller commands)
OCF: 0x000a (LE Set Advertising Enable command)
Enable: 0x01 (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:
...@@ -392,8 +427,9 @@ def main(): ...@@ -392,8 +427,9 @@ def main():
i += 1 i += 1
time.sleep(1 - time.monotonic() % 1) time.sleep(1 - time.monotonic() % 1)
except KeyboardInterrupt: except KeyboardInterrupt:
# Reset bt if not is_wifi:
subprocess.run("hcitool -i hci0 cmd 0x03 0x0003", shell=True) # Reset bt
subprocess.run("hcitool -i hci0 cmd 0x03 0x0003", shell=True)
if __name__ == '__main__': if __name__ == '__main__':
......
from scapy.layers.dot11 import Dot11, Dot11Beacon, RadioTap, sendp, Dot11Elt
# from scapy.all import hexdump # Used in commented code so uncomment when you uncomment the code
from uuid import getnode as get_mac
import os
import sys
import psutil
# The following is used to ensure that there is no issues with finding any local packages.
# Mainly used for accessing python-nan once upon a time but could still be useful now.
file_dir = os.path.dirname(__file__)
sys.path.append(file_dir)
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
iface = 'Wi-Fi' # This is the wifi interface on the drone, Wi-Fi seems to be a common windows name
# while linux seems to use wlan0 so the following checks if wlan0 is an interface then switches to that in that case.
addrs = psutil.net_if_addrs()
if "wlan0" in addrs.keys():
iface = "wlan0"
def beacon_wifi(mac_address, element_info):
"""
Broadcasts a wifi beacon from mac_address with the SSID as the given element_info.
:param mac_address: A array of integer values representing the devices mac_address
:param element_info: The info needed sent
:return: None
"""
dot11 = Dot11(type=0, subtype=8, addr1='ff:ff:ff:ff:ff:ff',
addr2=mac_address, addr3=mac_address)
dot_11_beacon = Dot11Beacon()
# Beacon that claims it needs a password for access
# dot_11_beacon = Dot11Beacon(cap='ESS+privacy')
# Actual information that should be sent
dot_11_element = Dot11Elt(ID='SSID', info=element_info, len=len(element_info))
# Test to ensure easy debug
# dot_11_element = Dot11Elt(ID='SSID', info='fakeTestNetwork', len=len('fakeTestNetwork'))
frame = RadioTap()/dot11 / dot_11_beacon / dot_11_element
# Following block adds fake security to the access point when detected so it will say on other devices
# that it needs a password.
# rsn = Dot11Elt(ID='RSNinfo', info=(
# '\x01\x00'
# '\x00\x0f\xac\x02'
# '\x02\x00'
# '\x00\x0f\xac\x04'
# '\x00\x0f\xac\x02'
# '\x01\x00'
# '\x00\x0f\xac\x02'
# '\x00\x00'))
# frame = RadioTap()/dot11/dot_11_beacon/ dot_11_element /rsn
# frame.show() # Prints a readable version of the frame that is being sent
# hexdump(frame) # Prints a hexdump of the frame that is being sent.
sendp(frame, iface=iface, inter=0.100, loop=1) # send the packet over interface iface every 100 milliseconds
mac = hex(get_mac()) # fetches device mac address
mac_arr = list(bytearray.fromhex(mac[2:])) # converts it into int
#vendor_info = '130042200100250B3FA14C1CEE522E25ADD5B000000000000000' # Static message to send
#beacon_wifi(mac_arr, vendor_info) # Actual call to the method
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment