_wifiutil_win.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. #!/usr/bin/env python3
  2. # vim: set fileencoding=utf-8
  3. """Implementations of wifi functions of Linux."""
  4. import re
  5. import platform
  6. import time
  7. import logging
  8. from ctypes import *
  9. from ctypes.wintypes import *
  10. from comtypes import GUID
  11. from .const import *
  12. from .profile import Profile
  13. if platform.release().lower() == 'xp':
  14. if platform.win32_ver()[2].lower() in ['sp2', 'sp3']:
  15. CLIENT_VERSION = 1
  16. else:
  17. CLIENT_VERSION = 2
  18. """
  19. Some types does not exist in python2 ctypes.wintypes so we fake them
  20. using how its defined in python3 ctypes.wintypes.
  21. """
  22. if not "PDWORD" in dir():
  23. PDWORD = POINTER(DWORD)
  24. if not "PWCHAR" in dir():
  25. PWCHAR= POINTER(WCHAR)
  26. ERROR_SUCCESS = 0
  27. WLAN_MAX_PHY_TYPE_NUMBER = 8
  28. DOT11_MAC_ADDRESS = c_ubyte * 6
  29. native_wifi = windll.wlanapi
  30. status_dict = [
  31. IFACE_INACTIVE,
  32. IFACE_CONNECTED,
  33. IFACE_CONNECTED,
  34. IFACE_DISCONNECTED,
  35. IFACE_DISCONNECTED,
  36. IFACE_CONNECTING,
  37. IFACE_CONNECTING,
  38. IFACE_CONNECTING
  39. ]
  40. auth_value_to_str_dict = {
  41. AUTH_ALG_OPEN: 'open',
  42. AUTH_ALG_SHARED: 'shared'
  43. }
  44. auth_str_to_value_dict = {
  45. 'open': AUTH_ALG_OPEN,
  46. 'shared': AUTH_ALG_SHARED
  47. }
  48. akm_str_to_value_dict = {
  49. 'NONE': AKM_TYPE_NONE,
  50. 'WPA': AKM_TYPE_WPA,
  51. 'WPAPSK': AKM_TYPE_WPAPSK,
  52. 'WPA2': AKM_TYPE_WPA2,
  53. 'WPA2PSK': AKM_TYPE_WPA2PSK,
  54. 'OTHER': AKM_TYPE_UNKNOWN
  55. }
  56. akm_value_to_str_dict = {
  57. AKM_TYPE_NONE: 'NONE',
  58. AKM_TYPE_WPA: 'WPA',
  59. AKM_TYPE_WPAPSK: 'WPAPSK',
  60. AKM_TYPE_WPA2: 'WPA2',
  61. AKM_TYPE_WPA2PSK: 'WPA2PSK',
  62. AKM_TYPE_UNKNOWN: 'OTHER'
  63. }
  64. cipher_str_to_value_dict = {
  65. 'NONE': CIPHER_TYPE_NONE,
  66. 'WEP': CIPHER_TYPE_WEP,
  67. 'TKIP': CIPHER_TYPE_TKIP,
  68. 'AES': CIPHER_TYPE_CCMP,
  69. 'OTHER': CIPHER_TYPE_UNKNOWN
  70. }
  71. cipher_value_to_str_dict = {
  72. CIPHER_TYPE_NONE: 'NONE',
  73. CIPHER_TYPE_WEP: 'WEP',
  74. CIPHER_TYPE_TKIP: 'TKIP',
  75. CIPHER_TYPE_CCMP: 'AES',
  76. CIPHER_TYPE_UNKNOWN: 'UNKNOWN'
  77. }
  78. class WLAN_INTERFACE_INFO(Structure):
  79. _fields_ = [
  80. ("InterfaceGuid", GUID),
  81. ("strInterfaceDescription", c_wchar * 256),
  82. ("isState", c_uint)
  83. ]
  84. class WLAN_INTERFACE_INFO_LIST(Structure):
  85. _fields_ = [
  86. ("dwNumberOfItems", DWORD),
  87. ("dwIndex", DWORD),
  88. ("InterfaceInfo", WLAN_INTERFACE_INFO * 1)
  89. ]
  90. class DOT11_SSID(Structure):
  91. _fields_ = [("uSSIDLength", c_ulong),
  92. ("ucSSID", c_char * 32)]
  93. class WLAN_RATE_SET(Structure):
  94. _fields_ = [
  95. ("uRateSetLength", c_ulong),
  96. ("usRateSet", c_ushort * 126)
  97. ]
  98. class WLAN_RAW_DATA(Structure):
  99. _fields_ = [
  100. ("dwDataSize", DWORD),
  101. ("DataBlob", c_byte * 1)
  102. ]
  103. class WLAN_AVAILABLE_NETWORK(Structure):
  104. _fields_ = [
  105. ("strProfileName", c_wchar * 256),
  106. ("dot11Ssid", DOT11_SSID),
  107. ("dot11BssType", c_uint),
  108. ("uNumberOfBssids", c_ulong),
  109. ("bNetworkConnectable", c_bool),
  110. ("wlanNotConnectableReason", c_uint),
  111. ("uNumberOfPhyTypes", c_ulong * WLAN_MAX_PHY_TYPE_NUMBER),
  112. ("dot11PhyTypes", c_uint),
  113. ("bMorePhyTypes", c_bool),
  114. ("wlanSignalQuality", c_ulong),
  115. ("bSecurityEnabled", c_bool),
  116. ("dot11DefaultAuthAlgorithm", c_uint),
  117. ("dot11DefaultCipherAlgorithm", c_uint),
  118. ("dwFlags", DWORD),
  119. ("dwReserved", DWORD)
  120. ]
  121. class WLAN_AVAILABLE_NETWORK_LIST(Structure):
  122. _fields_ = [
  123. ("dwNumberOfItems", DWORD),
  124. ("dwIndex", DWORD),
  125. ("Network", WLAN_AVAILABLE_NETWORK * 1)
  126. ]
  127. class WLAN_BSS_ENTRY(Structure):
  128. _fields_ = [
  129. ("dot11Ssid", DOT11_SSID),
  130. ("uPhyId", c_ulong),
  131. ("dot11Bssid", DOT11_MAC_ADDRESS),
  132. ("dot11BssType", c_uint),
  133. ("dot11BssPhyType", c_uint),
  134. ("lRssi", c_long),
  135. ("uLinkQuality", c_ulong),
  136. ("bInRegDomain", c_bool),
  137. ("usBeaconPeriod", c_ushort),
  138. ("ullTimestamp", c_ulonglong),
  139. ("ullHostTimestamp", c_ulonglong),
  140. ("usCapabilityInformation", c_ushort),
  141. ("ulChCenterFrequency", c_ulong),
  142. ("wlanRateSet", WLAN_RATE_SET),
  143. ("ulIeOffset", c_ulong),
  144. ("ulIeSize", c_ulong)
  145. ]
  146. class WLAN_BSS_LIST(Structure):
  147. _fields_ = [
  148. ("dwTotalSize", DWORD),
  149. ("dwNumberOfItems", DWORD),
  150. ("wlanBssEntries", WLAN_BSS_ENTRY * 1)
  151. ]
  152. class NDIS_OBJECT_HEADER(Structure):
  153. _fields_ = [
  154. ("Type", c_ubyte),
  155. ("Revision", c_ubyte),
  156. ("Size", c_ushort)
  157. ]
  158. class DOT11_BSSID_LIST(Structure):
  159. _fields_ = [
  160. ("Header", NDIS_OBJECT_HEADER),
  161. ("uNumOfEntries", c_ulong),
  162. ("uTotalNumOfEntries", c_ulong),
  163. ("BSSIDs", DOT11_MAC_ADDRESS * 1)
  164. ]
  165. class WLAN_CONNECTION_PARAMETERS(Structure):
  166. _fields_ = [
  167. ("wlanConnectionMode", c_uint),
  168. ("strProfile", c_wchar_p),
  169. ("pDot11Ssid", POINTER(DOT11_SSID)),
  170. ("pDesiredBssidList", POINTER(DOT11_BSSID_LIST)),
  171. ("dot11BssType", c_uint),
  172. ("dwFlags", DWORD)
  173. ]
  174. class WLAN_PROFILE_INFO(Structure):
  175. _fields_ = [
  176. ("strProfileName", c_wchar * 256),
  177. ("dwFlags", DWORD)
  178. ]
  179. class WLAN_PROFILE_INFO_LIST(Structure):
  180. _fields_ = [
  181. ("dwNumberOfItems", DWORD),
  182. ("dwIndex", DWORD),
  183. ("ProfileInfo", WLAN_PROFILE_INFO * 1)
  184. ]
  185. class WifiUtil():
  186. """WifiUtil implements the wifi functions in Windows."""
  187. _nego_version = DWORD()
  188. _handle = HANDLE()
  189. _ifaces = pointer(WLAN_INTERFACE_INFO_LIST())
  190. _logger = logging.getLogger('pywifi')
  191. def scan(self, obj):
  192. """Trigger the wifi interface to scan."""
  193. self._wlan_scan(self._handle, byref(obj['guid']))
  194. def scan_results(self, obj):
  195. """Get the AP list after scanning."""
  196. avail_network_list = pointer(WLAN_AVAILABLE_NETWORK_LIST())
  197. self._wlan_get_available_network_list(self._handle,
  198. byref(obj['guid']), byref(avail_network_list))
  199. networks = cast(avail_network_list.contents.Network,
  200. POINTER(WLAN_AVAILABLE_NETWORK))
  201. self._logger.debug("Scan found %d networks.",
  202. avail_network_list.contents.dwNumberOfItems)
  203. network_list = []
  204. for i in range(avail_network_list.contents.dwNumberOfItems):
  205. if networks[i].dot11BssType == 1 and networks[i].bNetworkConnectable :
  206. ssid = ''
  207. for j in range(networks[i].dot11Ssid.uSSIDLength):
  208. if networks[i].dot11Ssid.ucSSID != b'':
  209. ssid += "%c" % networks[i].dot11Ssid.ucSSID[j]
  210. bss_list = pointer(WLAN_BSS_LIST())
  211. self._wlan_get_network_bss_list(self._handle,
  212. byref(obj['guid']), byref(bss_list), networks[i].dot11Ssid, networks[i].bSecurityEnabled)
  213. bsses = cast(bss_list.contents.wlanBssEntries,
  214. POINTER(WLAN_BSS_ENTRY))
  215. if networks[i].bSecurityEnabled:
  216. akm = self._get_akm(networks[i].dot11DefaultCipherAlgorithm)
  217. auth_alg = self._get_auth_alg(networks[i].dot11DefaultAuthAlgorithm)
  218. else:
  219. akm = [AKM_TYPE_NONE]
  220. auth_alg = [AUTH_ALG_OPEN]
  221. for j in range(bss_list.contents.dwNumberOfItems):
  222. network = Profile()
  223. network.ssid = ssid
  224. network.bssid = ''
  225. for k in range(6):
  226. network.bssid += "%02x:" % bsses[j].dot11Bssid[k]
  227. network.signal = bsses[j].lRssi
  228. network.freq = bsses[j].ulChCenterFrequency
  229. network.auth = auth_alg
  230. network.akm = akm
  231. network_list.append(network)
  232. return network_list
  233. def connect(self, obj, params):
  234. """Connect to the specified AP."""
  235. connect_params = WLAN_CONNECTION_PARAMETERS()
  236. connect_params.wlanConnectionMode = 0 # Profile
  237. connect_params.dot11BssType = 1 # infra
  238. profile_name = create_unicode_buffer(params.ssid)
  239. connect_params.strProfile = profile_name.value
  240. ret = self._wlan_connect(
  241. self._handle, obj['guid'], byref(connect_params))
  242. self._logger.debug('connect result: %d', ret)
  243. def disconnect(self, obj):
  244. """Disconnect to the specified AP."""
  245. self._wlan_disconnect(self._handle, obj['guid'])
  246. def add_network_profile(self, obj, params):
  247. """Add an AP profile for connecting to afterward."""
  248. reason_code = DWORD()
  249. params.process_akm()
  250. profile_data = {}
  251. profile_data['ssid'] = params.ssid
  252. if AKM_TYPE_NONE in params.akm:
  253. profile_data['auth'] = auth_value_to_str_dict[params.auth]
  254. profile_data['encrypt'] = "none"
  255. else:
  256. profile_data['auth'] = akm_value_to_str_dict[params.akm[-1]]
  257. profile_data['encrypt'] = cipher_value_to_str_dict[params.cipher]
  258. profile_data['key'] = params.key
  259. profile_data['protected'] = 'false'
  260. profile_data['profile_name'] = params.ssid
  261. xml = """<?xml version="1.0"?>
  262. <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
  263. <name>{profile_name}</name>
  264. <SSIDConfig>
  265. <SSID>
  266. <name>{ssid}</name>
  267. </SSID>
  268. </SSIDConfig>
  269. <connectionType>ESS</connectionType>
  270. <connectionMode>manual</connectionMode>
  271. <MSM>
  272. <security>
  273. <authEncryption>
  274. <authentication>{auth}</authentication>
  275. <encryption>{encrypt}</encryption>
  276. <useOneX>false</useOneX>
  277. </authEncryption>
  278. """
  279. if AKM_TYPE_NONE not in params.akm:
  280. xml += """<sharedKey>
  281. <keyType>passPhrase</keyType>
  282. <protected>{protected}</protected>
  283. <keyMaterial>{key}</keyMaterial>
  284. </sharedKey>"""
  285. xml += """
  286. </security>
  287. </MSM>"""
  288. xml += """<MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
  289. <enableRandomization>false</enableRandomization>
  290. </MacRandomization>
  291. </WLANProfile>
  292. """
  293. xml = xml.format(**profile_data)
  294. status = self._wlan_set_profile(self._handle, obj['guid'], xml,
  295. True, byref(reason_code))
  296. if status != ERROR_SUCCESS:
  297. self._logger.debug("Status %d: Add profile failed", status)
  298. buf_size = DWORD(64)
  299. buf = create_unicode_buffer(64)
  300. self._wlan_reason_code_to_str(reason_code, buf_size, buf)
  301. return params
  302. def network_profile_name_list(self, obj):
  303. """Get AP profile names."""
  304. profile_list = pointer(WLAN_PROFILE_INFO_LIST())
  305. self._wlan_get_profile_list(self._handle,
  306. byref(obj['guid']),
  307. byref(profile_list))
  308. profiles = cast(profile_list.contents.ProfileInfo,
  309. POINTER(WLAN_PROFILE_INFO))
  310. profile_name_list = []
  311. for i in range(profile_list.contents.dwNumberOfItems):
  312. profile_name = ''
  313. for j in range(len(profiles[i].strProfileName)):
  314. profile_name += profiles[i].strProfileName[j]
  315. profile_name_list.append(profile_name)
  316. return profile_name_list
  317. def network_profiles(self, obj):
  318. """Get AP profiles."""
  319. profile_name_list = self.network_profile_name_list(obj)
  320. profile_list = []
  321. for profile_name in profile_name_list:
  322. profile = Profile()
  323. flags = DWORD()
  324. access = DWORD()
  325. xml = LPWSTR()
  326. self._wlan_get_profile(self._handle, obj['guid'],
  327. profile_name, byref(xml), byref(flags),
  328. byref(access))
  329. # fill profile info
  330. profile.ssid = re.search(r'<name>(.*)</name>', xml.value).group(1)
  331. auth = re.search(r'<authentication>(.*)</authentication>',
  332. xml.value).group(1).upper()
  333. profile.akm = []
  334. if auth not in akm_str_to_value_dict:
  335. if auth not in auth_str_to_value_dict:
  336. profile.auth = AUTH_ALG_OPEN
  337. else:
  338. profile.auth = auth_str_to_value_dict[auth]
  339. profile.akm.append(AKM_TYPE_NONE)
  340. else:
  341. profile.auth = AUTH_ALG_OPEN
  342. profile.akm.append(akm_str_to_value_dict[auth])
  343. profile_list.append(profile)
  344. return profile_list
  345. def remove_network_profile(self, obj, params):
  346. """Remove the specified AP profile."""
  347. self._logger.debug("delete profile: %s", params.ssid)
  348. str_buf = create_unicode_buffer(params.ssid)
  349. ret = self._wlan_delete_profile(self._handle, obj['guid'], str_buf)
  350. self._logger.debug("delete result %d", ret)
  351. def remove_all_network_profiles(self, obj):
  352. """Remove all the AP profiles."""
  353. profile_name_list = self.network_profile_name_list(obj)
  354. for profile_name in profile_name_list:
  355. self._logger.debug("delete profile: %s", profile_name)
  356. str_buf = create_unicode_buffer(profile_name)
  357. ret = self._wlan_delete_profile(self._handle, obj['guid'], str_buf)
  358. self._logger.debug("delete result %d", ret)
  359. def status(self, obj):
  360. """Get the wifi interface status."""
  361. data_size = DWORD()
  362. data = PDWORD()
  363. opcode_value_type = DWORD()
  364. self._wlan_query_interface(self._handle, obj['guid'], 6,
  365. byref(data_size), byref(data),
  366. byref(opcode_value_type))
  367. return status_dict[data.contents.value]
  368. def interfaces(self):
  369. """Get the wifi interface lists."""
  370. ifaces = []
  371. if self._wlan_open_handle(CLIENT_VERSION,
  372. byref(self._nego_version),
  373. byref(self._handle)) \
  374. is not ERROR_SUCCESS:
  375. self._logger.error("Open handle failed!")
  376. if self._wlan_enum_interfaces(self._handle, byref(self._ifaces)) \
  377. is not ERROR_SUCCESS:
  378. self._logger.error("Enum interface failed!")
  379. interfaces = cast(self._ifaces.contents.InterfaceInfo,
  380. POINTER(WLAN_INTERFACE_INFO))
  381. for i in range(0, self._ifaces.contents.dwNumberOfItems):
  382. iface = {}
  383. iface['guid'] = interfaces[i].InterfaceGuid
  384. iface['name'] = interfaces[i].strInterfaceDescription
  385. ifaces.append(iface)
  386. return ifaces
  387. def _wlan_open_handle(self, client_version, _nego_version, handle):
  388. func = native_wifi.WlanOpenHandle
  389. func.argtypes = [DWORD, c_void_p, POINTER(DWORD), POINTER(HANDLE)]
  390. func.restypes = [DWORD]
  391. return func(client_version, None, _nego_version, handle)
  392. def _wlan_close_handle(self, handle):
  393. func = native_wifi.WlanCloseHandle
  394. func.argtypes = [HANDLE, c_void_p]
  395. func.restypes = [DWORD]
  396. return func(handle, None)
  397. def _wlan_enum_interfaces(self, handle, ifaces):
  398. func = native_wifi.WlanEnumInterfaces
  399. func.argtypes = [HANDLE, c_void_p, POINTER(
  400. POINTER(WLAN_INTERFACE_INFO_LIST))]
  401. func.restypes = [DWORD]
  402. return func(handle, None, ifaces)
  403. def _wlan_get_available_network_list(self, handle,
  404. iface_guid,
  405. network_list):
  406. func = native_wifi.WlanGetAvailableNetworkList
  407. func.argtypes = [HANDLE, POINTER(GUID), DWORD, c_void_p, POINTER(
  408. POINTER(WLAN_AVAILABLE_NETWORK_LIST))]
  409. func.restypes = [DWORD]
  410. return func(handle, iface_guid, 2, None, network_list)
  411. def _wlan_get_network_bss_list(self, handle, iface_guid, bss_list, ssid = None, security = False):
  412. func = native_wifi.WlanGetNetworkBssList
  413. func.argtypes = [HANDLE, POINTER(GUID), POINTER(
  414. DOT11_SSID), c_uint, c_bool, c_void_p, POINTER(POINTER(WLAN_BSS_LIST))]
  415. func.restypes = [DWORD]
  416. return func(handle, iface_guid, ssid, 1, security, None, bss_list)
  417. def _wlan_scan(self, handle, iface_guid):
  418. func = native_wifi.WlanScan
  419. func.argtypes = [HANDLE, POINTER(GUID), POINTER(
  420. DOT11_SSID), POINTER(WLAN_RAW_DATA), c_void_p]
  421. func.restypes = [DWORD]
  422. return func(handle, iface_guid, None, None, None)
  423. def _wlan_connect(self, handle, iface_guid, params):
  424. func = native_wifi.WlanConnect
  425. func.argtypes = [HANDLE, POINTER(GUID), POINTER(
  426. WLAN_CONNECTION_PARAMETERS), c_void_p]
  427. func.restypes = [DWORD]
  428. return func(handle, iface_guid, params, None)
  429. def _wlan_set_profile(self, handle, iface_guid, xml, overwrite, reason_code):
  430. func = native_wifi.WlanSetProfile
  431. func.argtypes = [HANDLE, POINTER(
  432. GUID), DWORD, c_wchar_p, c_wchar_p, c_bool, c_void_p, POINTER(DWORD)]
  433. func.restypes = [DWORD]
  434. return func(handle, iface_guid, 2, xml, None, overwrite, None, reason_code)
  435. def _wlan_reason_code_to_str(self, reason_code, buf_size, buf):
  436. func = native_wifi.WlanReasonCodeToString
  437. func.argtypes = [DWORD, DWORD, PWCHAR, c_void_p]
  438. func.restypes = [DWORD]
  439. return func(reason_code, buf_size, buf, None)
  440. def _wlan_get_profile_list(self, handle, iface_guid, profile_list):
  441. func = native_wifi.WlanGetProfileList
  442. func.argtypes = [HANDLE, POINTER(GUID), c_void_p, POINTER(
  443. POINTER(WLAN_PROFILE_INFO_LIST))]
  444. func.restypes = [DWORD]
  445. return func(handle, iface_guid, None, profile_list)
  446. def _wlan_get_profile(self, handle, iface_guid, profile_name, xml, flags, access):
  447. func = native_wifi.WlanGetProfile
  448. func.argtypes = [HANDLE, POINTER(GUID), c_wchar_p, c_void_p, POINTER(
  449. c_wchar_p), POINTER(DWORD), POINTER(DWORD)]
  450. func.restypes = [DWORD]
  451. return func(handle, iface_guid, profile_name, None, xml, flags, access)
  452. def _wlan_delete_profile(self, handle, iface_guid, profile_name):
  453. func = native_wifi.WlanDeleteProfile
  454. func.argtypes = [HANDLE, POINTER(GUID), c_wchar_p, c_void_p]
  455. func.restypes = [DWORD]
  456. return func(handle, iface_guid, profile_name, None)
  457. def _wlan_query_interface(self, handle, iface_guid, opcode, data_size, data, opcode_value_type):
  458. func = native_wifi.WlanQueryInterface
  459. func.argtypes = [HANDLE, POINTER(GUID), DWORD, c_void_p, POINTER(
  460. DWORD), POINTER(POINTER(DWORD)), POINTER(DWORD)]
  461. func.restypes = [DWORD]
  462. return func(handle, iface_guid, opcode, None, data_size, data, opcode_value_type)
  463. def _wlan_disconnect(self, handle, iface_guid):
  464. func = native_wifi.WlanDisconnect
  465. func.argtypes = [HANDLE, POINTER(GUID), c_void_p]
  466. func.restypes = [DWORD]
  467. return func(handle, iface_guid, None)
  468. def _get_auth_alg(self, auth_val):
  469. auth_alg = []
  470. if auth_val in [1, 3, 4, 6, 7]:
  471. auth_alg.append(AUTH_ALG_OPEN)
  472. elif auth_val == 2:
  473. auth_alg.append(AUTH_ALG_SHARED)
  474. return auth_alg
  475. def _get_akm(self, akm_val):
  476. akm = []
  477. if akm_val == 2:
  478. akm.append(AKM_TYPE_WPAPSK)
  479. elif akm_val == 4:
  480. akm.append(AKM_TYPE_WPA2PSK)
  481. return akm