示例#1
0
def set_broadcastssid(server, id=0, intf_name=None, enable=False, ssid=None):
    """ enable or disable the broadcasting of the SSID
          @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface
        @type intf_name: str
        @param enable: set if the SSID should be broadcasted or if it is a hidden SSID
        @param enable: bool
    """
    if intf_name is None or ssid is None:
        return None, None

    # 1) create message
    msg_struct = Container(m_type=MSG_TYPE.MSG_SET_AP_BROADCASTSSID,
                           m_id=id,
                           p_version_length=len_of_string(VERSION),
                           p_version=VERSION,
                           m_size=0,
                           intf_name_size=len_of_string(intf_name),
                           intf_name=intf_name,
                           ssid_size=len_of_string(ssid),
                           ssid=ssid,
                           enabled=enable,
                           )
    send_and_receive_msg(server, msg_struct, msg_ap_broadcastssid.build, msg_ap_broadcastssid.parse, only_send=True)
def set_ap_dtiminterval(server, id=0, intf_name=None, dtim_interval=100):
    """ set the DTIM interval of the interface intf_name
        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface
        @type intf_name: str
        @param dtim_interval: DTIM interval
        @type dtim_interval: int
        @note: https://routerguide.net/dtim-interval-period-best-setting/

    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_AP_DTIMINTERVAL,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        dtim_interval=dtim_interval,
    )
    send_and_receive_msg(server, msg_struct, msg_ap_dtiminterval.build, msg_ap_dtiminterval.parse, only_send=True)
def set_beacon_interval(server, id=0, intf_name=None, beacon_interval=100):
    """
      set the beacon interval (in ms)
      default = 100ms
      different brands and models offer different allowable beacon interval ranges

      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str
      @param beacon_interval:
      @type beacon_interval: int
    """
    # create message container
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_BEACON_INTERVAL,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        beacon_interval=beacon_interval,
    )

    send_and_receive_msg(server,
                         msg_struct,
                         msg_beacon_interval.build,
                         msg_beacon_interval.parse,
                         only_send=True)
def send_msg_mean_sta_statistics_alpha(server,
                                       id=0,
                                       sta_ip=None,
                                       sta_port=0,
                                       alpha=0.1):
    """
      @param server: tuple (ip, port_num)
      @param id: message id
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
      @type sta_ip: str
      @param sta_port: socket port number of the station
      @type sta_port: int
      @param alpha: alpha from EWMA
      @type alpha: float

      @return: msg - received message
    """
    if not (isinstance(alpha, float) or isinstance(alpha, int)):
        return
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_MEAN_STA_STATISTICS_SET_ALPHA,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        sta_ip_size=len_of_string(sta_ip),
        sta_ip=sta_ip,
        sta_port=sta_port,
        alpha=alpha,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_mean_sta_statistics_alpha.build,
                         msg_mean_sta_statistics_alpha.parse,
                         only_send=True)
def set_hostapd_conf(server,
                     id=0,
                     intf_name=None,
                     conf_param=None,
                     conf_value=None):
    """
      set the beacon interval (in ms)
      default = 100ms
      different brands and models offer different allowable beacon interval ranges

      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str
    """
    # create message container
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_HOSTAPD_CONF,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        param_name_size=len_of_string(conf_param),
        param_name=conf_param,
        param_name_value_size=len_of_string(conf_value),
        param_value_name=conf_value,
    )

    send_and_receive_msg(server,
                         msg_struct,
                         msg_hostapd_conf.build,
                         msg_hostapd_conf.parse,
                         only_send=True)
def set_powersave_mode(server, id=0, powersave=True, intf_name=None, sta_ip=None, sta_port=0):
    """
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
      @type sta_ip: str
      @param sta_port: socket port number of the station
      @type sta_port: int
      """
    if intf_name is None:
        return
    """ set the powersave mode """
    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_POWERSAVEMODE,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        value=powersave,
    )
    send_and_receive_msg(server, msg_struct, msg_powersave.build, msg_powersave.parse, only_send=True)
def send_msg_mean_sta_statistics_time(server,
                                      id=0,
                                      sta_ip=None,
                                      sta_port=0,
                                      msec=100):
    """
      @param server: tuple (ip, port_num)
      @param id: message id
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
      @type sta_ip: str
      @param sta_port: socket port number of the station
      @type sta_port: int
      @param msec: statistics are collected during "msec" interval
      @type msec: int

      @return: msg - received message
    """
    if not isinstance(msec, int):
        return
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_MEAN_STA_STATISTICS_SET_TIME,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        sta_ip_size=len_of_string(sta_ip),
        sta_ip=sta_ip,
        sta_port=sta_port,
        msec=msec,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_mean_sta_statistics_time.build,
                         msg_mean_sta_statistics_time.parse,
                         only_send=True)
示例#8
0
def set_ap_rtsthreshold(server, id=0, intf_name=None, rts_threshold=0):
    """ enable or disable the broadcasting of the SSID
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str
    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_AP_RTSTHRESHOLD,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        rts_threshold=rts_threshold,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_ap_rtsthreshold.build,
                         msg_ap_rtsthreshold.parse,
                         only_send=True)
示例#9
0
def set_ap_guardinterval(server, id=0, intf_name=None, guard_interval=100):
    """ set the guard interval of the interface intf_name
        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface
        @type intf_name: str
        @param guard_interval: time used as guard interval between transmissions
        @type guard_interval: int
    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_AP_GUARDINTERVAL,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        guard_interval=guard_interval,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_ap_guardinterval.build,
                         msg_ap_guardinterval.parse,
                         only_send=True)
def set_snr_threshold(server,
                      id=0,
                      sta_ip=None,
                      sta_port=0,
                      intf_name=None,
                      threshold=10):
    """ set the SNR threshold in dBm. Send message to a station.

      @param server: tuple (ip, port_num)
      @param id: message id
      @param threshold: SNR threshold in dBm

    """
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_SNR_THRESHOLD,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        sta_ip_size=len_of_string(sta_ip),
        sta_ip=sta_ip,
        sta_port=sta_port,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        threshold=threshold,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_snr_threshold.build,
                         msg_snr_threshold.parse,
                         only_send=True)
def set_preamble(server, id=0, intf_name=None, preamble=0):
    """ set the preamble used in some interface
        0 = preamble LONG | 1 = preamble SHORT
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str
      @param preamble:
      @type sta_ip: bool

      @return: msg - received message
    """
    if intf_name is None:
        return
    if preamble != 1:
        preamble = 0  # default equals LONG

    # create message container
    msg_struct = Container(m_type=MSG_TYPE.MSG_SET_PREAMBLE,
                           m_id=id,
                           p_version_length=len_of_string(VERSION),
                           p_version=VERSION,
                           m_size=0,
                           intf_name_size=len_of_string(intf_name),
                           intf_name=intf_name,
                           preamble=preamble)
    send_and_receive_msg(server,
                         msg_struct,
                         msg_preamble.build,
                         msg_preamble.parse,
                         only_send=True)
def snr_threshold_interval_reached(server,
                                   id=0,
                                   sta_ip=None,
                                   sta_port=0,
                                   intf_name=None,
                                   interval=10):
    """ set the time between SNR scans in the station.

      @param server: tuple (ip, port_num)
      @param id: message id
      @param interval: interval in miliseconds
      @type interval: int
    """
    if interval <= 0:
        interval = -1  # disable
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_SNR_INTERVAL,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        sta_ip_size=len_of_string(sta_ip),
        sta_ip=sta_ip,
        sta_port=sta_port,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        interval=interval,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_snr_threshold_reached.build,
                         msg_snr_threshold_reached.parse,
                         only_send=True)
def set_ctsprotection_enabled(server, id=0, intf_name=None, enable=False):
    """ enable or disable RTS/CTS mechanism

        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface.
        @type intf_name: str
        @param enable: true activates RTS/CTS mechanism
        @param enable: bool

        @return msg: received message
        @return value:
    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_AP_BROADCASTSSID,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        enabled=enable,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_ctsprotection_enabled.build,
                         msg_ctsprotection_enabled.parse,
                         only_send=True)
示例#14
0
def get_uptime(server, id=0):
    """ get uptime

      @param server: tuple (ip, port_num)
      @param id: message id

      @return: msg - received message
          value (bytes or packets received or sent or lost)
    """
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_GET_UPTIME,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        uptime=0,
        idle=0,
    )

    error, msg = send_and_receive_msg(server, msg_struct, msg_uptime.build,
                                      msg_uptime.parse)
    if not error:
        uptime = msg['uptime'] if 'uptime' in msg else -1
        idle = msg['idle'] if 'idle' in msg else -1
    else:
        uptime = -1
        idle = -1

    return msg, uptime, idle
示例#15
0
def send_msg_bye(server, id=0, tcp_port=None):
    """ disconnects the ethanol device from the controller
      @param server: tuple (ip, port_num)
      @param id: message id
      @param tcp_port: socket port number of the device
      @type tcp_port: int
    """
    if (tcp_port is None):
        return None  # error

    # print "send_msg_bye id:", id
    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_BYE_TYPE,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        tcp_port=tcp_port,
    )
    error, msg = send_and_receive_msg(server,
                                      msg_struct,
                                      msg_bye.build,
                                      msg_bye.parse,
                                      only_send=True)

    return msg
def get_ap_dtiminterval(server, id=0, intf_name=None):
    """ get the DTIM interval set in the interface intf_name
        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface
        @type intf_name: str

        @return msg: received message
        @return value:
    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_GET_AP_DTIMINTERVAL,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        dtim_interval=-1,
    )
    error, msg = send_and_receive_msg(server, msg_struct, msg_ap_dtiminterval.build, msg_ap_dtiminterval.parse)
    if not error:
        value = msg['dtim_interval'] if 'dtim_interval' in msg else None
    else:
        value = None

    return msg, value
def get_preamble(server, id=0, intf_name=None):
    """ gets if the configured preamble is long or short
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str

      @return: msg - received message
    """
    # 1) create message
    if intf_name is None:
        return
    msg_struct = Container(m_type=MSG_TYPE.MSG_GET_PREAMBLE,
                           m_id=id,
                           p_version_length=len_of_string(VERSION),
                           p_version=VERSION,
                           m_size=0,
                           intf_name_size=len_of_string(intf_name),
                           intf_name=intf_name,
                           preamble=0)
    error, msg = send_and_receive_msg(server, msg_struct, msg_preamble.build,
                                      msg_preamble.parse)
    if not error:
        value = msg['preamble'] if 'preamble' in msg else -1
    else:
        value = -1

    return msg, value
示例#18
0
def set_metric(server, id=0, metric=0, enable=True, period=100):
    """ only for tests. the controller don't use this!!!
    """
    if metric == 0:
        return None
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_METRIC,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        enable=enable,
        period=period,
        metric=metric,
    )
    error, msg = send_and_receive_msg(server,
                                      msg_struct,
                                      msg_metric.build,
                                      msg_metric.parse,
                                      only_send=True)
    if not error and 'allowed' in msg and 'response' in msg:
        allowed = tri_boolean('allowed', msg)
        response = msg['response']
    else:
        allowed = True
        response = 0
    return msg, allowed, response
def station_trigger_transition(server, id=0, sta_ip=None, sta_port=0,
                               sta_mac=None, intf_name=None, mac_new_ap=None):
    """ sendo command to station to change to a new ap

      @param server: tuple (ip, port_num)
      @param id: message id

    """
    msg_struct = Container(m_type=MSG_TYPE.MSG_TRIGGER_TRANSITION,
                           m_id=id,
                           p_version_length=len_of_string(VERSION),
                           p_version=VERSION,
                           m_size=0,
                           sta_ip_size=len_of_string(sta_ip),
                           sta_ip=sta_ip,
                           sta_port=sta_port,
                           mac_addr_size=len_of_string(sta_mac),
                           mac_addr=sta_mac,
                           intf_name_size=len_of_string(intf_name),
                           intf_name=intf_name,
                           mac_new_ap_size=len_of_string(mac_new_ap),
                           mac_new_ap=mac_new_ap,
                           )
    error, msg = send_and_receive_msg(server, msg_struct, msg_station_trigger_transition.build,
                                      msg_station_trigger_transition.parse, only_send=True)
def get_ctsprotection_enabled(server, id=0, intf_name=None):
    """ Verify if RTS/CTS mechanism is activated

        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface.
        @type intf_name: str

        @return msg: received message
        @return value:
    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_GET_AP_BROADCASTSSID,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        enabled=False,
    )
    error, msg = send_and_receive_msg(server, msg_struct,
                                      msg_ctsprotection_enabled.build,
                                      msg_ctsprotection_enabled.parse)
    if not error:
        value = tri_boolean('enabled', msg)
    else:
        value = False

    return msg, value
示例#21
0
def changed_ap(server, id=0, status=0, current_ap=None, intf_name=None):
    """ verify is the interface is broadcasting the SSID
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: names of the wireless interface
      @type intf_name: list of str
      @param status: inform the status of the operation (result from change ap operation)
      @type status: int
      @param current_ap: MAC address of the ap
      @type current_ap: str
    """
    if (intf_name is None) or (current_ap is None):
        return

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_CHANGED_AP,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        current_ap_size=len_of_string(current_ap),
        current_ap=current_ap,
        status=status,
    )
    error, msg = send_and_receive_msg(server, msg_struct, msg_changed_ap.build, msg_changed_ap.parse, only_send=True)
def send_msg_mean_sta_statistics(server, id=0, sta_ip=None, sta_port=0):
    """
      @param server: tuple (ip, port_num)
      @param id: message id
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
      @type sta_ip: str
      @param sta_port: socket port number of the station
      @type sta_port: int

      @return: msg - received message
    """
    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_MEAN_STA_STATISTICS_GET,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        sta_ip_size=len_of_string(sta_ip),
        sta_ip=sta_ip,
        sta_port=sta_port,
        num=0,
        intf=[],
        mean_net_statistics=[],
    )
    error, msg = send_and_receive_msg(server, msg_struct,
                                      msg_mean_statistics.build,
                                      msg_mean_statistics.parse)
    value = {}
    if not error:
        for i in range(msg['num']):
            intf = msg['intf'][i]
            stats = msg['mean_net_statistics'][i]
            value[intf] = stats
    return msg, value
示例#23
0
def get_broadcastssid(server, id=0, intf_name=None, ssid=None):
    """ verify is the interface is broadcasting the SSID
        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface
        @type intf_name: str

        @return msg: received message
        @return value:
    """
    if intf_name is None or ssid is None:
        return None, None

    # 1) create message
    msg_struct = Container(m_type=MSG_TYPE.MSG_GET_AP_BROADCASTSSID,
                           m_id=id,
                           p_version_length=len_of_string(VERSION),
                           p_version=VERSION,
                           m_size=0,
                           intf_name_size=len_of_string(intf_name),
                           intf_name=intf_name,
                           ssid_size=len_of_string(ssid),
                           ssid=ssid,
                           enabled=False,
                           )
    error, msg = send_and_receive_msg(server, msg_struct, msg_ap_broadcastssid.build, msg_ap_broadcastssid.parse)
    if not error:
        value = tri_boolean('enabled', msg)
    else:
        value = None

    return msg, value
def get_beacon_interval(server, id=0, intf_name=None):
    """
    get beacon interval in miliseconds for the interface intf_name
    @param server: tuple (ip, port_num)
    @param id: message id
    @param intf_name: name of the wireless interface
    @type intf_name: str

    @return: -1 if an error occurs
    """
    if intf_name is None:
        return None, ERROR

    # 1) create message
    msg_struct = Container(m_type=MSG_TYPE.MSG_GET_BEACON_INTERVAL,
                           m_id=id,
                           p_version_length=len_of_string(VERSION),
                           p_version=VERSION,
                           m_size=0,
                           intf_name_size=len_of_string(intf_name),
                           intf_name=intf_name,
                           beacon_interval=0)
    error, msg = send_and_receive_msg(server, msg_struct,
                                      msg_beacon_interval.build,
                                      msg_beacon_interval.parse)
    if not error:
        value = msg['beacon_interval'] if 'beacon_interval' in msg else []
    else:
        value = []

    return msg, value
def set_ap_frameburstenabled(server, id=0, intf_name=None, enabled=False):
    """

        @param server: tuple (ip, port_num)
        @param id: message id
        @param intf_name: name of the wireless interface
        @type intf_name: str
        @param enabled: enables or disables frame burst
        @type enabled: bool
    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_SET_AP_FRAMEBURSTENABLED,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        enabled=enabled,
    )
    error, msg = send_and_receive_msg(server,
                                      msg_struct,
                                      msg_ap_frameburstenabled.build,
                                      msg_ap_frameburstenabled.parse,
                                      only_send=True)
示例#26
0
def get_powersave_mode(server, id=0, intf_name=None, sta_ip=None, sta_port=0):
    """ get if the powersave is set or not
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str
      @param sta_ip: ip address of the station that this message should be relayed to, if sta_ip is different from None
      @type sta_ip: str
      @param sta_port: socket port number of the station
      @type sta_port: int

      @return: msg - received message
    """

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_GET_POWERSAVEMODE,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        sta_ip_size=len_of_string(sta_ip),
        sta_ip=sta_ip,
        sta_port=sta_port,
        value=0,
    )
    error, msg = send_and_receive_msg(server, msg_struct, msg_powersave.build, msg_powersave.parse)
    if not error:
        value = True if ('value' in msg) and (msg['value'] == 1) else False
    else:
        value = False

    return msg, value
示例#27
0
def get_ap_rtsthreshold(server, id=0, intf_name=None):
    """ verify is the interface is broadcasting the SSID
      @param server: tuple (ip, port_num)
      @param id: message id
      @param intf_name: name of the wireless interface
      @type intf_name: str
      @return: msg, value
    """
    if intf_name is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_GET_AP_RTSTHRESHOLD,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        rts_threshold=0,
    )
    error, msg = send_and_receive_msg(server, msg_struct,
                                      msg_ap_rtsthreshold.build,
                                      msg_ap_rtsthreshold.parse)
    if not error:
        value = msg['enabled'] if 'enabled' in msg else None
    else:
        value = None

    return msg, value
def get_association(server,
                    id=0,
                    association_type=None,
                    mac_sta=None,
                    mac_ap=None):
    """ only for tests. the controller don't use this!!!
    """
    if (association_type is None) or (mac_sta is None) or (mac_ap is None):
        return None
    msg_struct = Container(
        m_type=association_type,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        mac_ap_size=len_of_string(mac_ap),
        mac_ap=mac_ap,
        mac_sta_size=len_of_string(mac_sta),
        mac_sta=mac_sta,
        allowed=True,
        response=0,
    )
    error, msg = send_and_receive_msg(server, msg_struct,
                                      msg_association.build,
                                      msg_association.parse)
    if not error and 'allowed' in msg and 'response' in msg:
        allowed = tri_boolean('allowed', msg)
        response = msg['response']
    else:
        allowed = True
        response = 0
    return msg, allowed, response
def get_hostapd_conf(server, id=0, intf_name=None, conf_param=None):
    """
    get beacon interval in miliseconds for the interface intf_name
    @param server: tuple (ip, port_num)
    @param id: message id
    @param intf_name: name of the wireless interface
    @type intf_name: str

    @return: -1 if an error occurs
    """
    if intf_name is None or conf_param is None:
        return None, None

    # 1) create message
    msg_struct = Container(
        m_type=MSG_TYPE.MSG_GET_HOSTAPD_CONF,
        m_id=id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        param_name_size=len_of_string(conf_param),
        param_name=conf_param,
        param_name_value_size=0,
        param_value_name=None,
    )
    error, msg = send_and_receive_msg(server, msg_struct,
                                      msg_hostapd_conf.build,
                                      msg_hostapd_conf.parse)
    if not error:
        value = msg['param_value_name'] if 'param_value_name' in msg else None
    else:
        value = None
    return msg, value
示例#30
0
def __msg_tos(server,
              m_type,
              msg_id=0,
              rule_id=-1,
              intf_name=None,
              proto=None,
              sip=None,
              sport=None,
              dip=None,
              dport=None,
              wmm_class=0):
    """ internal use only
    """
    if (rule_id < 1 and rule_id != -1) or (intf_name is None) or \
            (proto is None) or (wmm_class not in range(8)) or \
            (m_type not in [MSG_TYPE.MSG_TOS_ADD, MSG_TYPE.MSG_TOS_REPLACE]):
        return
    if isinstance(dport, int):
        dport = str(dport)
    if isinstance(dport, int):
        sport = str(sport)
    msg_struct = Container(
        m_type=m_type,
        m_id=msg_id,
        p_version_length=len_of_string(VERSION),
        p_version=VERSION,
        m_size=0,
        rule_id=rule_id,
        intf_name_size=len_of_string(intf_name),
        intf_name=intf_name,
        proto_size=len_of_string(proto),
        proto=proto,
        sip_size=len_of_string(sip),
        sip=sip,
        sport_size=len_of_string(sport),
        sport=sport,
        dip_size=len_of_string(dip),
        dip=dip,
        dport_size=len_of_string(dport),
        dport=dport,
        wmm_class=wmm_class,
    )
    send_and_receive_msg(server,
                         msg_struct,
                         msg_tos.build,
                         msg_tos.parse,
                         only_send=True)