1 | # -*- coding: utf-8 -*- |
---|
2 | """ |
---|
3 | ------------------------------------------------------------------------------ |
---|
4 | Mango 802.11 Reference Design Experiments Framework - Device Classes |
---|
5 | ------------------------------------------------------------------------------ |
---|
6 | License: Copyright 2019 Mango Communications, Inc. All rights reserved. |
---|
7 | Use and distribution subject to terms in LICENSE.txt |
---|
8 | ------------------------------------------------------------------------------ |
---|
9 | """ |
---|
10 | import sys |
---|
11 | |
---|
12 | __all__ = ['WlanDevice'] |
---|
13 | |
---|
14 | |
---|
15 | # Fix to support Python 2.x and 3.x |
---|
16 | if sys.version[0]=="3": long=None |
---|
17 | |
---|
18 | |
---|
19 | class WlanDevice(object): |
---|
20 | """Class for WLAN Device. This is the parent class for all wlan_exp node class definitions. |
---|
21 | This class also provides a node type for devices which exist in a wireless network but are not |
---|
22 | controlled by wlan_exp (i.e. a Wi-Fi client connected to an 802.11 Reference Design AP). |
---|
23 | |
---|
24 | Args: |
---|
25 | mac_address (int, str): Medium Access Control (MAC) address of the WLAN device (48-bits) |
---|
26 | The mac_address should be of the format: 0x0123456789AB or '01:23:45:67:89:AB' |
---|
27 | name (string): User generated description of the WLAN device |
---|
28 | ht_capable (bool): Indicates if device has PHY capable of HT (802.11n) rates |
---|
29 | |
---|
30 | **Class Members:** |
---|
31 | |
---|
32 | Attributes: |
---|
33 | name (string): User generated description of the WLAN device |
---|
34 | wlan_mac_address(int): MAC Address of WLAN Device |
---|
35 | ht_capable (bool): Indicates if device has PHY capable of HT (802.11n) rates |
---|
36 | """ |
---|
37 | name = None |
---|
38 | description = None |
---|
39 | |
---|
40 | wlan_mac_address = None |
---|
41 | |
---|
42 | ht_capable = None |
---|
43 | |
---|
44 | def __init__(self, mac_address, name=None, ht_capable=True): |
---|
45 | self.name = name |
---|
46 | self.ht_capable = ht_capable |
---|
47 | |
---|
48 | if mac_address is not None: |
---|
49 | if type(mac_address) in [int, long]: |
---|
50 | self.wlan_mac_address = mac_address |
---|
51 | elif type(mac_address) is str: |
---|
52 | try: |
---|
53 | import wlan_exp.util as util |
---|
54 | self.wlan_mac_address = util.str_to_mac_addr(mac_address) |
---|
55 | |
---|
56 | except TypeError: |
---|
57 | raise TypeError("MAC address is not valid") |
---|
58 | else: |
---|
59 | raise TypeError("MAC address is not valid") |
---|
60 | else: |
---|
61 | raise TypeError("MAC address is not valid") |
---|
62 | |
---|
63 | self.description = self.__repr__() |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | #------------------------------------------------------------------------- |
---|
68 | # WLAN Commands for the Device |
---|
69 | #------------------------------------------------------------------------- |
---|
70 | |
---|
71 | |
---|
72 | # ------------------------------------------------------------------------- |
---|
73 | # Misc methods for the Device |
---|
74 | # ------------------------------------------------------------------------- |
---|
75 | def __repr__(self): |
---|
76 | """Return device description""" |
---|
77 | msg = "" |
---|
78 | |
---|
79 | if self.wlan_mac_address is not None: |
---|
80 | from wlan_exp.util import mac_addr_to_str |
---|
81 | msg += "WLAN Device '{0}'".format(mac_addr_to_str(self.wlan_mac_address)) |
---|
82 | |
---|
83 | if self.name is not None: |
---|
84 | msg += " ({0})".format(self.name) |
---|
85 | else: |
---|
86 | msg += "Node not initialized." |
---|
87 | |
---|
88 | return msg |
---|
89 | |
---|
90 | # End Class WlanDevice |
---|
91 | |
---|
92 | |
---|