<?php

namespace app\models\mikrotik\wireless;

use yii\base\Model;
use Yii;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Interfaces extends Model {

    public $id;
    public $default_name;
    public $name;
    public $mtu;
    public $l2mtu;
    public $mac_address;
    public $arp;
    public $disable_running_check;
    public $interface_type;
    public $radio_name;
    public $mode;
    public $ssid;
    public $area;
    public $frequency_mode;
    public $country;
    public $antenna_gain;
    public $frequency;
    public $band;
    public $channel_width;
    public $scan_list;
    public $wireless_protocol;
    public $rate_set;
    public $supported_rates_b;
    public $supported_rates_a_g;
    public $basic_rates_b;
    public $basic_rates_a_g;
    public $max_station_count;
    public $distance;
    public $tx_power_mode;
    public $noise_floor_threshold;
    public $nv2_noise_floor_offset;
    public $burst_time;
    public $dfs_mode;
    public $antenna_mode;
    public $vlan_mode;
    public $vlan_id;
    public $wds_mode;
    public $wds_default_bridge;
    public $wds_default_cost;
    public $wds_cost_range;
    public $wds_ignore_ssid;
    public $update_stats_interval;
    public $bridge_mode;
    public $default_authentication;
    public $default_forwarding;
    public $default_ap_tx_limit;
    public $default_client_tx_limit;
    public $proprietary_extensions;
    public $wmm_support;
    public $hide_ssid;
    public $security_profile;
    public $interworking_profile;
    public $disconnect_timeout;
    public $on_fail_retry_time;
    public $preamble_mode;
    public $compression;
    public $allow_sharedkey;
    public $station_bridge_clone_mac;
    public $tdma_period_size;
    public $nv2_queue_count;
    public $nv2_qos;
    public $nv2_cell_radius;
    public $nv2_security;
    public $nv2_preshared_key;
    public $hw_retries;
    public $frame_lifetime;
    public $adaptive_noise_immunity;
    public $hw_fragmentation_threshold;
    public $hw_protection_mode;
    public $hw_protection_threshold;
    public $frequency_offset;
    public $rate_selection;
    public $multicast_helper;
    public $multicast_buffering;
    public $keepalive_frames;
    public $running;
    public $disabled;
    public $master_interface;

    public function rules() {
        return [
            ['id', 'string'],
            ['default_name', 'string'],
            ['name', 'string'],
            ['mtu', 'string'],
            ['l2mtu', 'string'],
            ['mac_address', 'string'],
            ['arp', 'string'],
            ['disable_running_check', 'string'],
            ['interface_type', 'string'],
            ['radio_name', 'string'],
            ['mode', 'string'],
            ['ssid', 'string'],
            ['area', 'string'],
            ['frequency_mode', 'string'],
            ['country', 'string'],
            ['antenna_gain', 'string'],
            ['frequency', 'string'],
            ['band', 'string'],
            ['channel_width', 'string'],
            ['scan_list', 'string'],
            ['wireless_protocol', 'string'],
            ['rate_set', 'string'],
            ['supported_rates_b', 'string'],
            ['supported_rates_a_g', 'string'],
            ['basic_rates_b', 'string'],
            ['basic_rates_a_g', 'string'],
            ['max_station_count', 'string'],
            ['distance', 'string'],
            ['tx_power_mode', 'string'],
            ['noise_floor_threshold', 'string'],
            ['nv2_noise_floor_offset', 'string'],
            ['burst_time', 'string'],
            ['dfs_mode', 'string'],
            ['antenna_mode', 'string'],
            ['vlan_mode', 'string'],
            ['vlan_id', 'string'],
            ['wds_mode', 'string'],
            ['wds_default_bridge', 'string'],
            ['wds_default_cost', 'string'],
            ['wds_cost_range', 'string'],
            ['wds_ignore_ssid', 'string'],
            ['update_stats_interval', 'string'],
            ['bridge_mode', 'string'],
            ['default_authentication', 'string'],
            ['default_forwarding', 'string'],
            ['default_ap_tx_limit', 'string'],
            ['default_client_tx_limit', 'string'],
            ['proprietary_extensions', 'string'],
            ['wmm_support', 'string'],
            ['hide_ssid', 'string'],
            ['security_profile', 'string'],
            ['interworking_profile', 'string'],
            ['disconnect_timeout', 'string'],
            ['on_fail_retry_time', 'string'],
            ['preamble_mode', 'string'],
            ['compression', 'string'],
            ['allow_sharedkey', 'string'],
            ['station_bridge_clone_mac', 'string'],
            ['tdma_period_size', 'string'],
            ['nv2_queue_count', 'string'],
            ['nv2_qos', 'string'],
            ['nv2_cell_radius', 'string'],
            ['nv2_security', 'string'],
            ['nv2_preshared_key', 'string'],
            ['hw_retries', 'string'],
            ['frame_lifetime', 'string'],
            ['adaptive_noise_immunity', 'string'],
            ['hw_fragmentation_threshold', 'string'],
            ['hw_protection_mode', 'string'],
            ['hw_protection_threshold', 'string'],
            ['frequency_offset', 'string'],
            ['rate_selection', 'string'],
            ['multicast_helper', 'string'],
            ['multicast_buffering', 'string'],
            ['keepalive_frames', 'string'],
            ['running', 'string'],
            ['disabled', 'string'],
            ['master_interface', 'string'],
        ];
    }

    public function getSecProf() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/wireless/security-profiles/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

    public function getNames() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/wireless/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $return[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $return;
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/wireless/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Interfaces();
                $c->id = $response->getProperty('.id');
                $c->default_name = $response->getProperty('default-name');
                $c->name = $response->getProperty('name');
                $c->mtu = $response->getProperty('mtu');
                $c->l2mtu = $response->getProperty('l2mtu');
                $c->mac_address = $response->getProperty('mac-address');
                $c->arp = $response->getProperty('arp');
                $c->disable_running_check = $response->getProperty('disable-running-check');
                $c->interface_type = $response->getProperty('interface-type');
                $c->radio_name = $response->getProperty('radio-name');
                $c->mode = $response->getProperty('mode');
                $c->ssid = $response->getProperty('ssid');
                $c->area = $response->getProperty('area');
                $c->frequency_mode = $response->getProperty('frequency-mode');
                $c->country = $response->getProperty('country');
                $c->antenna_gain = $response->getProperty('antenna-gain');
                $c->frequency = $response->getProperty('frequency');
                $c->band = $response->getProperty('band');
                $c->channel_width = $response->getProperty('channel-width');
                $c->scan_list = $response->getProperty('scan-list');
                $c->wireless_protocol = $response->getProperty('wireless-protocol');
                $c->rate_set = $response->getProperty('rate-set');
                $c->supported_rates_b = $response->getProperty('supported-rates-b');
                $c->supported_rates_a_g = $response->getProperty('supported-rates-a/g');
                $c->basic_rates_b = $response->getProperty('basic-rates-b');
                $c->basic_rates_a_g = $response->getProperty('basic-rates-a/g');
                $c->max_station_count = $response->getProperty('max-station-count');
                $c->distance = $response->getProperty('distance');
                $c->tx_power_mode = $response->getProperty('tx-power-mode');
                $c->noise_floor_threshold = $response->getProperty('noise-floor-threshold');
                $c->nv2_noise_floor_offset = $response->getProperty('nv2-noise-floor-offset');
                $c->burst_time = $response->getProperty('burst-time');
                $c->dfs_mode = $response->getProperty('dfs-mode');
                $c->antenna_mode = $response->getProperty('antenna-mode');
                $c->vlan_mode = $response->getProperty('vlan-mode');
                $c->vlan_id = $response->getProperty('vlan-id');
                $c->wds_mode = $response->getProperty('wds-mode');
                $c->wds_default_bridge = $response->getProperty('wds-default-bridge');
                $c->wds_default_cost = $response->getProperty('wds-default-cost');
                $c->wds_cost_range = $response->getProperty('wds-cost-range');
                $c->wds_ignore_ssid = $response->getProperty('wds-ignore-ssid');
                $c->update_stats_interval = $response->getProperty('update-stats-interval');
                $c->bridge_mode = $response->getProperty('bridge-mode');
                $c->default_authentication = $response->getProperty('default-authentication');
                $c->default_forwarding = $response->getProperty('default-forwarding');
                $c->default_ap_tx_limit = $response->getProperty('default-ap-tx-limit');
                $c->default_client_tx_limit = $response->getProperty('default-client-tx-limit');
                $c->proprietary_extensions = $response->getProperty('proprietary-extensions');
                $c->wmm_support = $response->getProperty('wmm-support');
                $c->hide_ssid = $response->getProperty('hide-ssid');
                $c->security_profile = $response->getProperty('security-profile');
                $c->interworking_profile = $response->getProperty('interworking-profile');
                $c->disconnect_timeout = $response->getProperty('disconnect-timeout');
                $c->on_fail_retry_time = $response->getProperty('on-fail-retry-time');
                $c->preamble_mode = $response->getProperty('preamble-mode');
                $c->compression = $response->getProperty('compression');
                $c->allow_sharedkey = $response->getProperty('allow-sharedkey');
                $c->station_bridge_clone_mac = $response->getProperty('station-bridge-clone-mac');
                $c->tdma_period_size = $response->getProperty('tdma-period-size');
                $c->nv2_queue_count = $response->getProperty('nv2-queue-count');
                $c->nv2_qos = $response->getProperty('nv2-qos');
                $c->nv2_cell_radius = $response->getProperty('nv2-cell-radius');
                $c->nv2_security = $response->getProperty('nv2-security');
                $c->nv2_preshared_key = $response->getProperty('nv2-preshared-key');
                $c->hw_retries = $response->getProperty('hw-retries');
                $c->frame_lifetime = $response->getProperty('frame-lifetime');
                $c->adaptive_noise_immunity = $response->getProperty('adaptive-noise-immunity');
                $c->hw_fragmentation_threshold = $response->getProperty('hw-fragmentation-threshold');
                $c->hw_protection_mode = $response->getProperty('hw-protection-mode');
                $c->hw_protection_threshold = $response->getProperty('hw-protection-threshold');
                $c->frequency_offset = $response->getProperty('frequency-offset');
                $c->rate_selection = $response->getProperty('rate-selection');
                $c->multicast_helper = $response->getProperty('multicast-helper');
                $c->multicast_buffering = $response->getProperty('multicast-buffering');
                $c->keepalive_frames = $response->getProperty('keepalive-frames');
                $c->running = $response->getProperty('running');
                $c->disabled = $response->getProperty('disabled');
                $return[] = $c;
            }
        }
        return $return;
    }

    public function get($id) {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/wireless/print');
        $getRequest->setQuery(RouterOS\Query::where('.id', $id));
        $responses = $connect->getConnection()->sendSync($getRequest);
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $this->id = $response->getProperty('.id');
                $this->default_name = $response->getProperty('default-name');
                $this->name = $response->getProperty('name');
                $this->mtu = $response->getProperty('mtu');
                $this->l2mtu = $response->getProperty('l2mtu');
                $this->mac_address = $response->getProperty('mac-address');
                $this->arp = $response->getProperty('arp');
                $this->disable_running_check = (($response->getProperty('disable-running-check') == 'true') ? true : false);
                $this->interface_type = $response->getProperty('interface-type');
                $this->radio_name = $response->getProperty('radio-name');
                $this->mode = $response->getProperty('mode');
                $this->ssid = $response->getProperty('ssid');
                $this->area = $response->getProperty('area');
                $this->frequency_mode = $response->getProperty('frequency-mode');
                $this->country = $response->getProperty('country');
                $this->antenna_gain = $response->getProperty('antenna-gain');
                $this->frequency = $response->getProperty('frequency');
                $this->band = $response->getProperty('band');
                $this->channel_width = $response->getProperty('channel-width');
                $this->scan_list = $response->getProperty('scan-list');
                $this->wireless_protocol = $response->getProperty('wireless-protocol');
                $this->rate_set = $response->getProperty('rate-set');
                $this->supported_rates_b = $response->getProperty('supported-rates-b');
                $this->supported_rates_a_g = $response->getProperty('supported-rates-a/g');
                $this->basic_rates_b = $response->getProperty('basic-rates-b');
                $this->basic_rates_a_g = $response->getProperty('basic-rates-a/g');
                $this->max_station_count = $response->getProperty('max-station-count');
                $this->distance = $response->getProperty('distance');
                $this->tx_power_mode = $response->getProperty('tx-power-mode');
                $this->noise_floor_threshold = $response->getProperty('noise-floor-threshold');
                $this->nv2_noise_floor_offset = $response->getProperty('nv2-noise-floor-offset');
                $this->burst_time = $response->getProperty('burst-time');
                $this->dfs_mode = $response->getProperty('dfs-mode');
                $this->antenna_mode = $response->getProperty('antenna-mode');
                $this->vlan_mode = $response->getProperty('vlan-mode');
                $this->vlan_id = $response->getProperty('vlan-id');
                $this->wds_mode = $response->getProperty('wds-mode');
                $this->wds_default_bridge = $response->getProperty('wds-default-bridge');
                $this->wds_default_cost = $response->getProperty('wds-default-cost');
                $this->wds_cost_range = $response->getProperty('wds-cost-range');
                $this->wds_ignore_ssid = (($response->getProperty('wds-ignore-ssid') == 'true') ? true : false);
                $this->update_stats_interval = $response->getProperty('update-stats-interval');
                $this->bridge_mode = $response->getProperty('bridge-mode');
                $this->default_authentication = (($response->getProperty('default-authentication') == 'true') ? true : false);
                $this->default_forwarding = (($response->getProperty('default-forwarding') == 'true') ? true : false);
                $this->default_ap_tx_limit = $response->getProperty('default-ap-tx-limit');
                $this->default_client_tx_limit = $response->getProperty('default-client-tx-limit');
                $this->proprietary_extensions = $response->getProperty('proprietary-extensions');
                $this->wmm_support = $response->getProperty('wmm-support');
                $this->hide_ssid = (($response->getProperty('hide-ssid') == 'true') ? true : false);
                $this->security_profile = $response->getProperty('security-profile');
                $this->interworking_profile = $response->getProperty('interworking-profile');
                $this->disconnect_timeout = $response->getProperty('disconnect-timeout');
                $this->on_fail_retry_time = $response->getProperty('on-fail-retry-time');
                $this->preamble_mode = $response->getProperty('preamble-mode');
                $this->compression = (($response->getProperty('compression') == 'true') ? true : false);
                $this->allow_sharedkey = (($response->getProperty('allow-sharedkey') == 'true') ? true : false);
                $this->station_bridge_clone_mac = $response->getProperty('station-bridge-clone-mac');
                $this->tdma_period_size = $response->getProperty('tdma-period-size');
                $this->nv2_queue_count = $response->getProperty('nv2-queue-count');
                $this->nv2_qos = $response->getProperty('nv2-qos');
                $this->nv2_cell_radius = $response->getProperty('nv2-cell-radius');
                $this->nv2_security = $response->getProperty('nv2-security');
                $this->nv2_preshared_key = $response->getProperty('nv2-preshared-key');
                $this->hw_retries = $response->getProperty('hw-retries');
                $this->frame_lifetime = $response->getProperty('frame-lifetime');
                $this->adaptive_noise_immunity = $response->getProperty('adaptive-noise-immunity');
                $this->hw_fragmentation_threshold = $response->getProperty('hw-fragmentation-threshold');
                $this->hw_protection_mode = $response->getProperty('hw-protection-mode');
                $this->hw_protection_threshold = $response->getProperty('hw-protection-threshold');
                $this->frequency_offset = $response->getProperty('frequency-offset');
                $this->rate_selection = $response->getProperty('rate-selection');
                $this->multicast_helper = $response->getProperty('multicast-helper');
                $this->multicast_buffering = $response->getProperty('multicast-buffering');
                $this->keepalive_frames = $response->getProperty('keepalive-frames');
                $this->running = (($response->getProperty('running') == 'true') ? true : false);
                $this->disabled = (($response->getProperty('disabled') == 'true') ? true : false);
                $this->master_interface = $response->getProperty('master-interface');
            }
        }
        return;
    }

    public function update($id) {
        $c = new Interfaces();
        $c->get($id);
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/wireless/set');
        $setRequest->setargument('.id', $id);
        if ($this->default_name != $c->default_name) {
            $setRequest->setargument('default-name', $this->default_name);
        }
        if ($this->name != $c->name) {
            $setRequest->setargument('name', $this->name);
        }
        if ($this->mtu != $c->mtu) {
            $setRequest->setargument('mtu', $this->mtu);
        }
        if ($this->l2mtu != $c->l2mtu) {
            $setRequest->setargument('l2mtu', $this->l2mtu);
        }
        if ($this->mac_address != $c->mac_address) {
            $setRequest->setargument('mac-address', $this->mac_address);
        }
        if ($this->arp != $c->arp) {
            $setRequest->setargument('arp', $this->arp);
        }
        $setRequest->setargument('disable-running-check', (($this->disable_running_check == true) ? "true" : "false"));
        if ($this->interface_type != $c->interface_type) {
            $setRequest->setargument('interface-type', $this->interface_type);
        }
        if ($this->radio_name != $c->radio_name) {
            $setRequest->setargument('radio-name', $this->radio_name);
        }
        if ($this->mode != $c->mode) {
            $setRequest->setargument('mode', $this->mode);
        }
        if ($this->ssid != $c->ssid) {
            $setRequest->setargument('ssid', $this->ssid);
        }
        if ($this->area != $c->area) {
            $setRequest->setargument('area', $this->area);
        }
        if ($this->frequency_mode != $c->frequency_mode) {
            $setRequest->setargument('frequency-mode', $this->frequency_mode);
        }
        if ($this->country != $c->country) {
            $setRequest->setargument('country', $this->country);
        }
        if ($this->antenna_gain != $c->antenna_gain) {
            $setRequest->setargument('antenna-gain', $this->antenna_gain);
        }
        if ($this->frequency != $c->frequency) {
            $setRequest->setargument('frequency', $this->frequency);
        }
        if ($this->band != $c->band) {
            $setRequest->setargument('band', $this->band);
        }
        if ($this->channel_width != $c->channel_width) {
            $setRequest->setargument('channel-width', $this->channel_width);
        }
        if ($this->scan_list != $c->scan_list) {
            $setRequest->setargument('scan-list', $this->scan_list);
        }
        if ($this->wireless_protocol != $c->wireless_protocol) {
            $setRequest->setargument('wireless-protocol', $this->wireless_protocol);
        }
        if ($this->rate_set != $c->rate_set) {
            $setRequest->setargument('rate-set', $this->rate_set);
        }
        if ($this->supported_rates_b != $c->supported_rates_b) {
            $setRequest->setargument('supported-rates-b', $this->supported_rates_b);
        }
        if ($this->supported_rates_a_g != $c->supported_rates_a_g) {
            $setRequest->setargument('supported-rates-a/g', $this->supported_rates_a_g);
        }
        if ($this->basic_rates_b != $c->basic_rates_b) {
            $setRequest->setargument('basic-rates-b', $this->basic_rates_b);
        }
        if ($this->basic_rates_a_g != $c->basic_rates_a_g) {
            $setRequest->setargument('basic-rates-a/g', $this->basic_rates_a_g);
        }
        if ($this->max_station_count != $c->max_station_count) {
            $setRequest->setargument('max-station-count', $this->max_station_count);
        }
        if ($this->distance != $c->distance) {
            $setRequest->setargument('distance', $this->distance);
        }
        if ($this->tx_power_mode != $c->tx_power_mode) {
            $setRequest->setargument('tx-power-mode', $this->tx_power_mode);
        }
        if ($this->noise_floor_threshold != $c->noise_floor_threshold) {
            $setRequest->setargument('noise-floor-threshold', $this->noise_floor_threshold);
        }
        if ($this->nv2_noise_floor_offset != $c->nv2_noise_floor_offset) {
            $setRequest->setargument('nv2-noise-floor-offset', $this->nv2_noise_floor_offset);
        }
        if ($this->burst_time != $c->burst_time) {
            $setRequest->setargument('burst-time', $this->burst_time);
        }
        if ($this->dfs_mode != $c->dfs_mode) {
            $setRequest->setargument('dfs-mode', $this->dfs_mode);
        }
        if ($this->antenna_mode != $c->antenna_mode) {
            $setRequest->setargument('antenna-mode', $this->antenna_mode);
        }
        if ($this->vlan_mode != $c->vlan_mode) {
            $setRequest->setargument('vlan-mode', $this->vlan_mode);
        }
        if ($this->vlan_id != $c->vlan_id) {
            $setRequest->setargument('vlan-id', $this->vlan_id);
        }
        if ($this->wds_mode != $c->wds_mode) {
            $setRequest->setargument('wds-mode', $this->wds_mode);
        }
        if ($this->wds_default_bridge != $c->wds_default_bridge) {
            $setRequest->setargument('wds-default-bridge', $this->wds_default_bridge);
        }
        if ($this->wds_default_cost != $c->wds_default_cost) {
            $setRequest->setargument('wds-default-cost', $this->wds_default_cost);
        }
        if ($this->wds_cost_range != $c->wds_cost_range) {
            $setRequest->setargument('wds-cost-range', $this->wds_cost_range);
        }
        $setRequest->setargument('wds-ignore-ssid', (($this->wds_ignore_ssid == true) ? "true" : "false"));
        if ($this->update_stats_interval != $c->update_stats_interval) {
            $setRequest->setargument('update-stats-interval', $this->update_stats_interval);
        }
        if ($this->bridge_mode != $c->bridge_mode) {
            $setRequest->setargument('bridge-mode', $this->bridge_mode);
        }
        $setRequest->setargument('default-authentication', (($this->default_authentication == true) ? "true" : "false"));
        $setRequest->setargument('default-forwarding', (($this->default_forwarding == true) ? "true" : "false"));
        if ($this->default_ap_tx_limit != $c->default_ap_tx_limit) {
            $setRequest->setargument('default-ap-tx-limit', $this->default_ap_tx_limit);
        }
        if ($this->default_client_tx_limit != $c->default_client_tx_limit) {
            $setRequest->setargument('default-client-tx-limit', $this->default_client_tx_limit);
        }
        if ($this->proprietary_extensions != $c->proprietary_extensions) {
            $setRequest->setargument('proprietary-extensions', $this->proprietary_extensions);
        }
        if ($this->wmm_support != $c->wmm_support) {
            $setRequest->setargument('wmm-support', $this->wmm_support);
        }
        $setRequest->setargument('hide-ssid', (($this->hide_ssid == true) ? "true" : "false"));
        if ($this->security_profile != $c->security_profile) {
            $setRequest->setargument('security-profile', $this->security_profile);
        }
        if ($this->interworking_profile != $c->interworking_profile) {
            $setRequest->setargument('interworking-profile', $this->interworking_profile);
        }
        if ($this->disconnect_timeout != $c->disconnect_timeout) {
            $setRequest->setargument('disconnect-timeout', $this->disconnect_timeout);
        }
        if ($this->on_fail_retry_time != $c->on_fail_retry_time) {
            $setRequest->setargument('on-fail-retry-time', $this->on_fail_retry_time);
        }
        if ($this->preamble_mode != $c->preamble_mode) {
            $setRequest->setargument('preamble-mode', $this->preamble_mode);
        }
        $setRequest->setargument('compression', (($this->compression == true) ? "true" : "false"));
        $setRequest->setargument('allow-sharedkey', (($this->allow_sharedkey == true) ? "true" : "false"));
        if ($this->station_bridge_clone_mac != $c->station_bridge_clone_mac) {
            $setRequest->setargument('station-bridge-clone-mac', $this->station_bridge_clone_mac);
        }
        if ($this->tdma_period_size != $c->tdma_period_size) {
            $setRequest->setargument('tdma-period-size', $this->tdma_period_size);
        }
        if ($this->nv2_queue_count != $c->nv2_queue_count) {
            $setRequest->setargument('nv2-queue-count', $this->nv2_queue_count);
        }
        if ($this->nv2_qos != $c->nv2_qos) {
            $setRequest->setargument('nv2-qos', $this->nv2_qos);
        }
        if ($this->nv2_cell_radius != $c->nv2_cell_radius) {
            $setRequest->setargument('nv2-cell-radius', $this->nv2_cell_radius);
        }
        if ($this->nv2_security != $c->nv2_security) {
            $setRequest->setargument('nv2-security', $this->nv2_security);
        }
        if ($this->nv2_preshared_key != $c->nv2_preshared_key) {
            $setRequest->setargument('nv2-preshared-key', $this->nv2_preshared_key);
        }
        if ($this->hw_retries != $c->hw_retries) {
            $setRequest->setargument('hw-retries', $this->hw_retries);
        }
        if ($this->frame_lifetime != $c->frame_lifetime) {
            $setRequest->setargument('frame-lifetime', $this->frame_lifetime);
        }
        if ($this->adaptive_noise_immunity != $c->adaptive_noise_immunity) {
            $setRequest->setargument('adaptive-noise-immunity', $this->adaptive_noise_immunity);
        }
        if ($this->hw_fragmentation_threshold != $c->hw_fragmentation_threshold) {
            $setRequest->setargument('hw-fragmentation-threshold', $this->hw_fragmentation_threshold);
        }
        if ($this->hw_protection_mode != $c->hw_protection_mode) {
            $setRequest->setargument('hw-protection-mode', $this->hw_protection_mode);
        }
        if ($this->hw_protection_threshold != $c->hw_protection_threshold) {
            $setRequest->setargument('hw-protection-threshold', $this->hw_protection_threshold);
        }
        if ($this->frequency_offset != $c->frequency_offset) {
            $setRequest->setargument('frequency-offset', $this->frequency_offset);
        }
        if ($this->rate_selection != $c->rate_selection) {
            $setRequest->setargument('rate-selection', $this->rate_selection);
        }
        if ($this->multicast_helper != $c->multicast_helper) {
            $setRequest->setargument('multicast-helper', $this->multicast_helper);
        }
        if ($this->multicast_buffering != $c->multicast_buffering) {
            $setRequest->setargument('multicast-buffering', $this->multicast_buffering);
        }
        if ($this->keepalive_frames != $c->keepalive_frames) {
            $setRequest->setargument('keepalive-frames', $this->keepalive_frames);
        }
        if ($this->master_interface != $c->master_interface) {
            $setRequest->setargument('master-interface', $this->master_interface);
        }
        if (isset($unset)) {
            $unsetRequest = new RouterOS\Request('/interface/wireless/unset');
            foreach ($unset as $value) {
                $unsetRequest->setArgument('.id', $id);
                $unsetRequest->setArgument('value-name', $value);
                $resp = $connect->getConnection()->sendSync($unsetRequest);
                if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
                    if (!isset($re)) {
                        $re = '';
                    } $re.= ' ' . $resp->getProperty('message');
                }
            }
        } $resp = $connect->getConnection()->sendSync($setRequest);
        if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
            if (isset($re)) {
                $re.= ' ' . $resp->getProperty('message');
            } else {
                $re = $resp->getProperty('message');
            }
        } if (isset($re)) {
            return $re;
        } else {
            return '1';
        }
    }

    public function disable($id) {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/wireless/disable');
        $setRequest->setArgument('.id', $id);
        $connect->getConnection()->sendSync($setRequest);
        return;
    }

    public function enable($id) {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/wireless/enable');
        $setRequest->setArgument('.id', $id);
        $connect->getConnection()->sendSync($setRequest);
        return;
    }

    public function create() {
        $connect = MikrotikConnect::Instance();
        $setRequest = new RouterOS\Request('/interface/wireless/add');
        if ($this->default_name != "") {
            $setRequest->setargument('default-name', $this->default_name);
        }
        if ($this->name != "") {
            $setRequest->setargument('name', $this->name);
        }
        if ($this->master_interface != "") {
            $setRequest->setargument('master-interface', $this->master_interface);
        }
        if ($this->mtu != "") {
            $setRequest->setargument('mtu', $this->mtu);
        }
        if ($this->l2mtu != "") {
            $setRequest->setargument('l2mtu', $this->l2mtu);
        }
        if ($this->mac_address != "") {
            $setRequest->setargument('mac-address', $this->mac_address);
        }
        if ($this->arp != "") {
            $setRequest->setargument('arp', $this->arp);
        }
        if ($this->disable_running_check != "") {
            $setRequest->setargument('disable-running-check', (($this->disable_running_check == true) ? "true" : "false"));
        }
        if ($this->interface_type != "") {
            $setRequest->setargument('interface-type', $this->interface_type);
        }
        if ($this->radio_name != "") {
            $setRequest->setargument('radio-name', $this->radio_name);
        }
        if ($this->mode != "") {
            $setRequest->setargument('mode', $this->mode);
        }
        if ($this->ssid != "") {
            $setRequest->setargument('ssid', $this->ssid);
        }
        if ($this->area != "") {
            $setRequest->setargument('area', $this->area);
        }
        if ($this->frequency_mode != "") {
            $setRequest->setargument('frequency-mode', $this->frequency_mode);
        }
        if ($this->country != "") {
            $setRequest->setargument('country', $this->country);
        }
        if ($this->antenna_gain != "") {
            $setRequest->setargument('antenna-gain', $this->antenna_gain);
        }
        if ($this->frequency != "") {
            $setRequest->setargument('frequency', $this->frequency);
        }
        if ($this->band != "") {
            $setRequest->setargument('band', $this->band);
        }
        if ($this->channel_width != "") {
            $setRequest->setargument('channel-width', $this->channel_width);
        }
        if ($this->scan_list != "") {
            $setRequest->setargument('scan-list', $this->scan_list);
        }
        if ($this->wireless_protocol != "") {
            $setRequest->setargument('wireless-protocol', $this->wireless_protocol);
        }
        if ($this->rate_set != "") {
            $setRequest->setargument('rate-set', $this->rate_set);
        }
        if ($this->supported_rates_b != "") {
            $setRequest->setargument('supported-rates-b', $this->supported_rates_b);
        }
        if ($this->supported_rates_a_g != "") {
            $setRequest->setargument('supported-rates-a/g', $this->supported_rates_a_g);
        }
        if ($this->basic_rates_b != "") {
            $setRequest->setargument('basic-rates-b', $this->basic_rates_b);
        }
        if ($this->basic_rates_a_g != "") {
            $setRequest->setargument('basic-rates-a/g', $this->basic_rates_a_g);
        }
        if ($this->max_station_count != "") {
            $setRequest->setargument('max-station-count', $this->max_station_count);
        }
        if ($this->distance != "") {
            $setRequest->setargument('distance', $this->distance);
        }
        if ($this->tx_power_mode != "") {
            $setRequest->setargument('tx-power-mode', $this->tx_power_mode);
        }
        if ($this->noise_floor_threshold != "") {
            $setRequest->setargument('noise-floor-threshold', $this->noise_floor_threshold);
        }
        if ($this->nv2_noise_floor_offset != "") {
            $setRequest->setargument('nv2-noise-floor-offset', $this->nv2_noise_floor_offset);
        }
        if ($this->burst_time != "") {
            $setRequest->setargument('burst-time', $this->burst_time);
        }
        if ($this->dfs_mode != "") {
            $setRequest->setargument('dfs-mode', $this->dfs_mode);
        }
        if ($this->antenna_mode != "") {
            $setRequest->setargument('antenna-mode', $this->antenna_mode);
        }
        if ($this->vlan_mode != "") {
            $setRequest->setargument('vlan-mode', $this->vlan_mode);
        }
        if ($this->vlan_id != "") {
            $setRequest->setargument('vlan-id', $this->vlan_id);
        }
        if ($this->wds_mode != "") {
            $setRequest->setargument('wds-mode', $this->wds_mode);
        }
        if ($this->wds_default_bridge != "") {
            $setRequest->setargument('wds-default-bridge', $this->wds_default_bridge);
        }
        if ($this->wds_default_cost != "") {
            $setRequest->setargument('wds-default-cost', $this->wds_default_cost);
        }
        if ($this->wds_cost_range != "") {
            $setRequest->setargument('wds-cost-range', $this->wds_cost_range);
        }
        if ($this->wds_ignore_ssid != "") {
            $setRequest->setargument('wds-ignore-ssid', (($this->wds_ignore_ssid == true) ? "true" : "false"));
        }
        if ($this->update_stats_interval != "") {
            $setRequest->setargument('update-stats-interval', $this->update_stats_interval);
        }
        if ($this->bridge_mode != "") {
            $setRequest->setargument('bridge-mode', $this->bridge_mode);
        }
        if ($this->default_authentication != "") {
            $setRequest->setargument('default-authentication', (($this->default_authentication == true) ? "true" : "false"));
        }
        if ($this->default_forwarding != "") {
            $setRequest->setargument('default-forwarding', (($this->default_forwarding == true) ? "true" : "false"));
        }
        if ($this->default_ap_tx_limit != "") {
            $setRequest->setargument('default-ap-tx-limit', $this->default_ap_tx_limit);
        }
        if ($this->default_client_tx_limit != "") {
            $setRequest->setargument('default-client-tx-limit', $this->default_client_tx_limit);
        }
        if ($this->proprietary_extensions != "") {
            $setRequest->setargument('proprietary-extensions', $this->proprietary_extensions);
        }
        if ($this->wmm_support != "") {
            $setRequest->setargument('wmm-support', $this->wmm_support);
        }
        if ($this->hide_ssid != "") {
            $setRequest->setargument('hide-ssid', (($this->hide_ssid == true) ? "true" : "false"));
        }
        if ($this->security_profile != "") {
            $setRequest->setargument('security-profile', $this->security_profile);
        }
        if ($this->interworking_profile != "") {
            $setRequest->setargument('interworking-profile', $this->interworking_profile);
        }
        if ($this->disconnect_timeout != "") {
            $setRequest->setargument('disconnect-timeout', $this->disconnect_timeout);
        }
        if ($this->on_fail_retry_time != "") {
            $setRequest->setargument('on-fail-retry-time', $this->on_fail_retry_time);
        }
        if ($this->preamble_mode != "") {
            $setRequest->setargument('preamble-mode', $this->preamble_mode);
        }
        if ($this->compression != "") {
            $setRequest->setargument('compression', (($this->compression == true) ? "true" : "false"));
        }
        if ($this->allow_sharedkey != "") {
            $setRequest->setargument('allow-sharedkey', (($this->allow_sharedkey == true) ? "true" : "false"));
        }
        if ($this->station_bridge_clone_mac != "") {
            $setRequest->setargument('station-bridge-clone-mac', $this->station_bridge_clone_mac);
        }
        if ($this->tdma_period_size != "") {
            $setRequest->setargument('tdma-period-size', $this->tdma_period_size);
        }
        if ($this->nv2_queue_count != "") {
            $setRequest->setargument('nv2-queue-count', $this->nv2_queue_count);
        }
        if ($this->nv2_qos != "") {
            $setRequest->setargument('nv2-qos', $this->nv2_qos);
        }
        if ($this->nv2_cell_radius != "") {
            $setRequest->setargument('nv2-cell-radius', $this->nv2_cell_radius);
        }
        if ($this->nv2_security != "") {
            $setRequest->setargument('nv2-security', $this->nv2_security);
        }
        if ($this->nv2_preshared_key != "") {
            $setRequest->setargument('nv2-preshared-key', $this->nv2_preshared_key);
        }
        if ($this->hw_retries != "") {
            $setRequest->setargument('hw-retries', $this->hw_retries);
        }
        if ($this->frame_lifetime != "") {
            $setRequest->setargument('frame-lifetime', $this->frame_lifetime);
        }
        if ($this->adaptive_noise_immunity != "") {
            $setRequest->setargument('adaptive-noise-immunity', $this->adaptive_noise_immunity);
        }
        if ($this->hw_fragmentation_threshold != "") {
            $setRequest->setargument('hw-fragmentation-threshold', $this->hw_fragmentation_threshold);
        }
        if ($this->hw_protection_mode != "") {
            $setRequest->setargument('hw-protection-mode', $this->hw_protection_mode);
        }
        if ($this->hw_protection_threshold != "") {
            $setRequest->setargument('hw-protection-threshold', $this->hw_protection_threshold);
        }
        if ($this->frequency_offset != "") {
            $setRequest->setargument('frequency-offset', $this->frequency_offset);
        }
        if ($this->rate_selection != "") {
            $setRequest->setargument('rate-selection', $this->rate_selection);
        }
        if ($this->multicast_helper != "") {
            $setRequest->setargument('multicast-helper', $this->multicast_helper);
        }
        if ($this->multicast_buffering != "") {
            $setRequest->setargument('multicast-buffering', $this->multicast_buffering);
        }
        if ($this->keepalive_frames != "") {
            $setRequest->setargument('keepalive-frames', $this->keepalive_frames);
        }
        $resp = $connect->getConnection()->sendSync($setRequest);
        if ($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
            return $resp->getProperty('message');
        } else {
            return '1';
        }
    }

    public function delete($id) {
        $connect = MikrotikConnect::Instance();
        $util = new RouterOS\Util($connect->getConnection());
        $util->setMenu('/interface/wireless');
        $util->remove(RouterOS\Query::where('.id', $id));
        return;
    }

    public function getBridgeNames() {

        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/bridge/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $ret = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $ret[$response->getProperty('name')] = $response->getProperty('name');
            }
        }
        return $ret;
    }

}
