summaryrefslogtreecommitdiffstats
path: root/kernel/drivers/net/wireless/ti/wl1251/reg.h
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/drivers/net/wireless/ti/wl1251/reg.h')
-rw-r--r--kernel/drivers/net/wireless/ti/wl1251/reg.h655
1 files changed, 655 insertions, 0 deletions
diff --git a/kernel/drivers/net/wireless/ti/wl1251/reg.h b/kernel/drivers/net/wireless/ti/wl1251/reg.h
new file mode 100644
index 000000000..a5809019c
--- /dev/null
+++ b/kernel/drivers/net/wireless/ti/wl1251/reg.h
@@ -0,0 +1,655 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __REG_H__
+#define __REG_H__
+
+#include <linux/bitops.h>
+
+#define REGISTERS_BASE 0x00300000
+#define DRPW_BASE 0x00310000
+
+#define REGISTERS_DOWN_SIZE 0x00008800
+#define REGISTERS_WORK_SIZE 0x0000b000
+
+#define HW_ACCESS_ELP_CTRL_REG_ADDR 0x1FFFC
+
+/* ELP register commands */
+#define ELPCTRL_WAKE_UP 0x1
+#define ELPCTRL_WAKE_UP_WLAN_READY 0x5
+#define ELPCTRL_SLEEP 0x0
+/* ELP WLAN_READY bit */
+#define ELPCTRL_WLAN_READY 0x2
+
+/* Device Configuration registers*/
+#define SOR_CFG (REGISTERS_BASE + 0x0800)
+#define ECPU_CTRL (REGISTERS_BASE + 0x0804)
+#define HI_CFG (REGISTERS_BASE + 0x0808)
+
+/* EEPROM registers */
+#define EE_START (REGISTERS_BASE + 0x080C)
+#define EE_CTL (REGISTERS_BASE + 0x2000)
+#define EE_DATA (REGISTERS_BASE + 0x2004)
+#define EE_ADDR (REGISTERS_BASE + 0x2008)
+
+#define EE_CTL_READ 2
+
+#define CHIP_ID_B (REGISTERS_BASE + 0x5674)
+
+#define CHIP_ID_1251_PG10 (0x7010101)
+#define CHIP_ID_1251_PG11 (0x7020101)
+#define CHIP_ID_1251_PG12 (0x7030101)
+
+#define ENABLE (REGISTERS_BASE + 0x5450)
+
+/* Power Management registers */
+#define ELP_CFG_MODE (REGISTERS_BASE + 0x5804)
+#define ELP_CMD (REGISTERS_BASE + 0x5808)
+#define PLL_CAL_TIME (REGISTERS_BASE + 0x5810)
+#define CLK_REQ_TIME (REGISTERS_BASE + 0x5814)
+#define CLK_BUF_TIME (REGISTERS_BASE + 0x5818)
+
+#define CFG_PLL_SYNC_CNT (REGISTERS_BASE + 0x5820)
+
+/* Scratch Pad registers*/
+#define SCR_PAD0 (REGISTERS_BASE + 0x5608)
+#define SCR_PAD1 (REGISTERS_BASE + 0x560C)
+#define SCR_PAD2 (REGISTERS_BASE + 0x5610)
+#define SCR_PAD3 (REGISTERS_BASE + 0x5614)
+#define SCR_PAD4 (REGISTERS_BASE + 0x5618)
+#define SCR_PAD4_SET (REGISTERS_BASE + 0x561C)
+#define SCR_PAD4_CLR (REGISTERS_BASE + 0x5620)
+#define SCR_PAD5 (REGISTERS_BASE + 0x5624)
+#define SCR_PAD5_SET (REGISTERS_BASE + 0x5628)
+#define SCR_PAD5_CLR (REGISTERS_BASE + 0x562C)
+#define SCR_PAD6 (REGISTERS_BASE + 0x5630)
+#define SCR_PAD7 (REGISTERS_BASE + 0x5634)
+#define SCR_PAD8 (REGISTERS_BASE + 0x5638)
+#define SCR_PAD9 (REGISTERS_BASE + 0x563C)
+
+/* Spare registers*/
+#define SPARE_A1 (REGISTERS_BASE + 0x0994)
+#define SPARE_A2 (REGISTERS_BASE + 0x0998)
+#define SPARE_A3 (REGISTERS_BASE + 0x099C)
+#define SPARE_A4 (REGISTERS_BASE + 0x09A0)
+#define SPARE_A5 (REGISTERS_BASE + 0x09A4)
+#define SPARE_A6 (REGISTERS_BASE + 0x09A8)
+#define SPARE_A7 (REGISTERS_BASE + 0x09AC)
+#define SPARE_A8 (REGISTERS_BASE + 0x09B0)
+#define SPARE_B1 (REGISTERS_BASE + 0x5420)
+#define SPARE_B2 (REGISTERS_BASE + 0x5424)
+#define SPARE_B3 (REGISTERS_BASE + 0x5428)
+#define SPARE_B4 (REGISTERS_BASE + 0x542C)
+#define SPARE_B5 (REGISTERS_BASE + 0x5430)
+#define SPARE_B6 (REGISTERS_BASE + 0x5434)
+#define SPARE_B7 (REGISTERS_BASE + 0x5438)
+#define SPARE_B8 (REGISTERS_BASE + 0x543C)
+
+enum wl12xx_acx_int_reg {
+ ACX_REG_INTERRUPT_TRIG,
+ ACX_REG_INTERRUPT_TRIG_H,
+
+/*=============================================
+ Host Interrupt Mask Register - 32bit (RW)
+ ------------------------------------------
+ Setting a bit in this register masks the
+ corresponding interrupt to the host.
+ 0 - RX0 - Rx first dubble buffer Data Interrupt
+ 1 - TXD - Tx Data Interrupt
+ 2 - TXXFR - Tx Transfer Interrupt
+ 3 - RX1 - Rx second dubble buffer Data Interrupt
+ 4 - RXXFR - Rx Transfer Interrupt
+ 5 - EVENT_A - Event Mailbox interrupt
+ 6 - EVENT_B - Event Mailbox interrupt
+ 7 - WNONHST - Wake On Host Interrupt
+ 8 - TRACE_A - Debug Trace interrupt
+ 9 - TRACE_B - Debug Trace interrupt
+ 10 - CDCMP - Command Complete Interrupt
+ 11 -
+ 12 -
+ 13 -
+ 14 - ICOMP - Initialization Complete Interrupt
+ 16 - SG SE - Soft Gemini - Sense enable interrupt
+ 17 - SG SD - Soft Gemini - Sense disable interrupt
+ 18 - -
+ 19 - -
+ 20 - -
+ 21- -
+ Default: 0x0001
+*==============================================*/
+ ACX_REG_INTERRUPT_MASK,
+
+/*=============================================
+ Host Interrupt Mask Set 16bit, (Write only)
+ ------------------------------------------
+ Setting a bit in this register sets
+ the corresponding bin in ACX_HINT_MASK register
+ without effecting the mask
+ state of other bits (0 = no effect).
+==============================================*/
+ ACX_REG_HINT_MASK_SET,
+
+/*=============================================
+ Host Interrupt Mask Clear 16bit,(Write only)
+ ------------------------------------------
+ Setting a bit in this register clears
+ the corresponding bin in ACX_HINT_MASK register
+ without effecting the mask
+ state of other bits (0 = no effect).
+=============================================*/
+ ACX_REG_HINT_MASK_CLR,
+
+/*=============================================
+ Host Interrupt Status Nondestructive Read
+ 16bit,(Read only)
+ ------------------------------------------
+ The host can read this register to determine
+ which interrupts are active.
+ Reading this register doesn't
+ effect its content.
+=============================================*/
+ ACX_REG_INTERRUPT_NO_CLEAR,
+
+/*=============================================
+ Host Interrupt Status Clear on Read Register
+ 16bit,(Read only)
+ ------------------------------------------
+ The host can read this register to determine
+ which interrupts are active.
+ Reading this register clears it,
+ thus making all interrupts inactive.
+==============================================*/
+ ACX_REG_INTERRUPT_CLEAR,
+
+/*=============================================
+ Host Interrupt Acknowledge Register
+ 16bit,(Write only)
+ ------------------------------------------
+ The host can set individual bits in this
+ register to clear (acknowledge) the corresp.
+ interrupt status bits in the HINT_STS_CLR and
+ HINT_STS_ND registers, thus making the
+ assotiated interrupt inactive. (0-no effect)
+==============================================*/
+ ACX_REG_INTERRUPT_ACK,
+
+/*===============================================
+ Host Software Reset - 32bit RW
+ ------------------------------------------
+ [31:1] Reserved
+ 0 SOFT_RESET Soft Reset - When this bit is set,
+ it holds the Wlan hardware in a soft reset state.
+ This reset disables all MAC and baseband processor
+ clocks except the CardBus/PCI interface clock.
+ It also initializes all MAC state machines except
+ the host interface. It does not reload the
+ contents of the EEPROM. When this bit is cleared
+ (not self-clearing), the Wlan hardware
+ exits the software reset state.
+===============================================*/
+ ACX_REG_SLV_SOFT_RESET,
+
+/*===============================================
+ EEPROM Burst Read Start - 32bit RW
+ ------------------------------------------
+ [31:1] Reserved
+ 0 ACX_EE_START - EEPROM Burst Read Start 0
+ Setting this bit starts a burst read from
+ the external EEPROM.
+ If this bit is set (after reset) before an EEPROM read/write,
+ the burst read starts at EEPROM address 0.
+ Otherwise, it starts at the address
+ following the address of the previous access.
+ TheWlan hardware hardware clears this bit automatically.
+
+ Default: 0x00000000
+*================================================*/
+ ACX_REG_EE_START,
+
+/* Embedded ARM CPU Control */
+
+/*===============================================
+ Halt eCPU - 32bit RW
+ ------------------------------------------
+ 0 HALT_ECPU Halt Embedded CPU - This bit is the
+ compliment of bit 1 (MDATA2) in the SOR_CFG register.
+ During a hardware reset, this bit holds
+ the inverse of MDATA2.
+ When downloading firmware from the host,
+ set this bit (pull down MDATA2).
+ The host clears this bit after downloading the firmware into
+ zero-wait-state SSRAM.
+ When loading firmware from Flash, clear this bit (pull up MDATA2)
+ so that the eCPU can run the bootloader code in Flash
+ HALT_ECPU eCPU State
+ --------------------
+ 1 halt eCPU
+ 0 enable eCPU
+ ===============================================*/
+ ACX_REG_ECPU_CONTROL,
+
+ ACX_REG_TABLE_LEN
+};
+
+#define ACX_SLV_SOFT_RESET_BIT BIT(0)
+#define ACX_REG_EEPROM_START_BIT BIT(0)
+
+/* Command/Information Mailbox Pointers */
+
+/*===============================================
+ Command Mailbox Pointer - 32bit RW
+ ------------------------------------------
+ This register holds the start address of
+ the command mailbox located in the Wlan hardware memory.
+ The host must read this pointer after a reset to
+ find the location of the command mailbox.
+ The Wlan hardware initializes the command mailbox
+ pointer with the default address of the command mailbox.
+ The command mailbox pointer is not valid until after
+ the host receives the Init Complete interrupt from
+ the Wlan hardware.
+ ===============================================*/
+#define REG_COMMAND_MAILBOX_PTR (SCR_PAD0)
+
+/*===============================================
+ Information Mailbox Pointer - 32bit RW
+ ------------------------------------------
+ This register holds the start address of
+ the information mailbox located in the Wlan hardware memory.
+ The host must read this pointer after a reset to find
+ the location of the information mailbox.
+ The Wlan hardware initializes the information mailbox pointer
+ with the default address of the information mailbox.
+ The information mailbox pointer is not valid
+ until after the host receives the Init Complete interrupt from
+ the Wlan hardware.
+ ===============================================*/
+#define REG_EVENT_MAILBOX_PTR (SCR_PAD1)
+
+
+/* Misc */
+
+#define REG_ENABLE_TX_RX (ENABLE)
+/*
+ * Rx configuration (filter) information element
+ * ---------------------------------------------
+ */
+#define REG_RX_CONFIG (RX_CFG)
+#define REG_RX_FILTER (RX_FILTER_CFG)
+
+
+#define RX_CFG_ENABLE_PHY_HEADER_PLCP 0x0002
+
+/* promiscuous - receives all valid frames */
+#define RX_CFG_PROMISCUOUS 0x0008
+
+/* receives frames from any BSSID */
+#define RX_CFG_BSSID 0x0020
+
+/* receives frames destined to any MAC address */
+#define RX_CFG_MAC 0x0010
+
+#define RX_CFG_ENABLE_ONLY_MY_DEST_MAC 0x0010
+#define RX_CFG_ENABLE_ANY_DEST_MAC 0x0000
+#define RX_CFG_ENABLE_ONLY_MY_BSSID 0x0020
+#define RX_CFG_ENABLE_ANY_BSSID 0x0000
+
+/* discards all broadcast frames */
+#define RX_CFG_DISABLE_BCAST 0x0200
+
+#define RX_CFG_ENABLE_ONLY_MY_SSID 0x0400
+#define RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR 0x0800
+#define RX_CFG_COPY_RX_STATUS 0x2000
+#define RX_CFG_TSF 0x10000
+
+#define RX_CONFIG_OPTION_ANY_DST_MY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
+ RX_CFG_ENABLE_ONLY_MY_BSSID)
+
+#define RX_CONFIG_OPTION_MY_DST_ANY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
+ | RX_CFG_ENABLE_ANY_BSSID)
+
+#define RX_CONFIG_OPTION_ANY_DST_ANY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
+ RX_CFG_ENABLE_ANY_BSSID)
+
+#define RX_CONFIG_OPTION_MY_DST_MY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
+ | RX_CFG_ENABLE_ONLY_MY_BSSID)
+
+#define RX_CONFIG_OPTION_FOR_SCAN (RX_CFG_ENABLE_PHY_HEADER_PLCP \
+ | RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR \
+ | RX_CFG_COPY_RX_STATUS | RX_CFG_TSF)
+
+#define RX_CONFIG_OPTION_FOR_MEASUREMENT (RX_CFG_ENABLE_ANY_DEST_MAC)
+
+#define RX_CONFIG_OPTION_FOR_JOIN (RX_CFG_ENABLE_ONLY_MY_BSSID | \
+ RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
+
+#define RX_CONFIG_OPTION_FOR_IBSS_JOIN (RX_CFG_ENABLE_ONLY_MY_SSID | \
+ RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
+
+#define RX_FILTER_OPTION_DEF (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
+ | CFG_RX_CTL_EN | CFG_RX_BCN_EN\
+ | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
+
+#define RX_FILTER_OPTION_FILTER_ALL 0
+
+#define RX_FILTER_OPTION_DEF_PRSP_BCN (CFG_RX_PRSP_EN | CFG_RX_MGMT_EN\
+ | CFG_RX_RCTS_ACK | CFG_RX_BCN_EN)
+
+#define RX_FILTER_OPTION_JOIN (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
+ | CFG_RX_BCN_EN | CFG_RX_AUTH_EN\
+ | CFG_RX_ASSOC_EN | CFG_RX_RCTS_ACK\
+ | CFG_RX_PRSP_EN)
+
+
+/*===============================================
+ EEPROM Read/Write Request 32bit RW
+ ------------------------------------------
+ 1 EE_READ - EEPROM Read Request 1 - Setting this bit
+ loads a single byte of data into the EE_DATA
+ register from the EEPROM location specified in
+ the EE_ADDR register.
+ The Wlan hardware hardware clears this bit automatically.
+ EE_DATA is valid when this bit is cleared.
+
+ 0 EE_WRITE - EEPROM Write Request - Setting this bit
+ writes a single byte of data from the EE_DATA register into the
+ EEPROM location specified in the EE_ADDR register.
+ The Wlan hardware hardware clears this bit automatically.
+*===============================================*/
+#define EE_CTL (REGISTERS_BASE + 0x2000)
+#define ACX_EE_CTL_REG EE_CTL
+#define EE_WRITE 0x00000001ul
+#define EE_READ 0x00000002ul
+
+/*===============================================
+ EEPROM Address - 32bit RW
+ ------------------------------------------
+ This register specifies the address
+ within the EEPROM from/to which to read/write data.
+ ===============================================*/
+#define EE_ADDR (REGISTERS_BASE + 0x2008)
+#define ACX_EE_ADDR_REG EE_ADDR
+
+/*===============================================
+ EEPROM Data - 32bit RW
+ ------------------------------------------
+ This register either holds the read 8 bits of
+ data from the EEPROM or the write data
+ to be written to the EEPROM.
+ ===============================================*/
+#define EE_DATA (REGISTERS_BASE + 0x2004)
+#define ACX_EE_DATA_REG EE_DATA
+
+#define EEPROM_ACCESS_TO 10000 /* timeout counter */
+#define START_EEPROM_MGR 0x00000001
+
+/*===============================================
+ EEPROM Base Address - 32bit RW
+ ------------------------------------------
+ This register holds the upper nine bits
+ [23:15] of the 24-bit Wlan hardware memory
+ address for burst reads from EEPROM accesses.
+ The EEPROM provides the lower 15 bits of this address.
+ The MSB of the address from the EEPROM is ignored.
+ ===============================================*/
+#define ACX_EE_CFG EE_CFG
+
+/*===============================================
+ GPIO Output Values -32bit, RW
+ ------------------------------------------
+ [31:16] Reserved
+ [15: 0] Specify the output values (at the output driver inputs) for
+ GPIO[15:0], respectively.
+ ===============================================*/
+#define ACX_GPIO_OUT_REG GPIO_OUT
+#define ACX_MAX_GPIO_LINES 15
+
+/*===============================================
+ Contention window -32bit, RW
+ ------------------------------------------
+ [31:26] Reserved
+ [25:16] Max (0x3ff)
+ [15:07] Reserved
+ [06:00] Current contention window value - default is 0x1F
+ ===============================================*/
+#define ACX_CONT_WIND_CFG_REG CONT_WIND_CFG
+#define ACX_CONT_WIND_MIN_MASK 0x0000007f
+#define ACX_CONT_WIND_MAX 0x03ff0000
+
+/*===============================================
+ HI_CFG Interface Configuration Register Values
+ ------------------------------------------
+ ===============================================*/
+#define HI_CFG_UART_ENABLE 0x00000004
+#define HI_CFG_RST232_ENABLE 0x00000008
+#define HI_CFG_CLOCK_REQ_SELECT 0x00000010
+#define HI_CFG_HOST_INT_ENABLE 0x00000020
+#define HI_CFG_VLYNQ_OUTPUT_ENABLE 0x00000040
+#define HI_CFG_HOST_INT_ACTIVE_LOW 0x00000080
+#define HI_CFG_UART_TX_OUT_GPIO_15 0x00000100
+#define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200
+#define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400
+
+/*
+ * NOTE: USE_ACTIVE_HIGH compilation flag should be defined in makefile
+ * for platforms using active high interrupt level
+ */
+#ifdef USE_ACTIVE_HIGH
+#define HI_CFG_DEF_VAL \
+ (HI_CFG_UART_ENABLE | \
+ HI_CFG_RST232_ENABLE | \
+ HI_CFG_CLOCK_REQ_SELECT | \
+ HI_CFG_HOST_INT_ENABLE)
+#else
+#define HI_CFG_DEF_VAL \
+ (HI_CFG_UART_ENABLE | \
+ HI_CFG_RST232_ENABLE | \
+ HI_CFG_CLOCK_REQ_SELECT | \
+ HI_CFG_HOST_INT_ENABLE)
+
+#endif
+
+#define REF_FREQ_19_2 0
+#define REF_FREQ_26_0 1
+#define REF_FREQ_38_4 2
+#define REF_FREQ_40_0 3
+#define REF_FREQ_33_6 4
+#define REF_FREQ_NUM 5
+
+#define LUT_PARAM_INTEGER_DIVIDER 0
+#define LUT_PARAM_FRACTIONAL_DIVIDER 1
+#define LUT_PARAM_ATTN_BB 2
+#define LUT_PARAM_ALPHA_BB 3
+#define LUT_PARAM_STOP_TIME_BB 4
+#define LUT_PARAM_BB_PLL_LOOP_FILTER 5
+#define LUT_PARAM_NUM 6
+
+#define ACX_EEPROMLESS_IND_REG (SCR_PAD4)
+#define USE_EEPROM 0
+#define SOFT_RESET_MAX_TIME 1000000
+#define SOFT_RESET_STALL_TIME 1000
+#define NVS_DATA_BUNDARY_ALIGNMENT 4
+
+
+/* Firmware image load chunk size */
+#define CHUNK_SIZE 512
+
+/* Firmware image header size */
+#define FW_HDR_SIZE 8
+
+#define ECPU_CONTROL_HALT 0x00000101
+
+
+/******************************************************************************
+
+ CHANNELS, BAND & REG DOMAINS definitions
+
+******************************************************************************/
+
+
+enum {
+ RADIO_BAND_2_4GHZ = 0, /* 2.4 Ghz band */
+ RADIO_BAND_5GHZ = 1, /* 5 Ghz band */
+ RADIO_BAND_JAPAN_4_9_GHZ = 2,
+ DEFAULT_BAND = RADIO_BAND_2_4GHZ,
+ INVALID_BAND = 0xFE,
+ MAX_RADIO_BANDS = 0xFF
+};
+
+enum {
+ NO_RATE = 0,
+ RATE_1MBPS = 0x0A,
+ RATE_2MBPS = 0x14,
+ RATE_5_5MBPS = 0x37,
+ RATE_6MBPS = 0x0B,
+ RATE_9MBPS = 0x0F,
+ RATE_11MBPS = 0x6E,
+ RATE_12MBPS = 0x0A,
+ RATE_18MBPS = 0x0E,
+ RATE_22MBPS = 0xDC,
+ RATE_24MBPS = 0x09,
+ RATE_36MBPS = 0x0D,
+ RATE_48MBPS = 0x08,
+ RATE_54MBPS = 0x0C
+};
+
+enum {
+ RATE_INDEX_1MBPS = 0,
+ RATE_INDEX_2MBPS = 1,
+ RATE_INDEX_5_5MBPS = 2,
+ RATE_INDEX_6MBPS = 3,
+ RATE_INDEX_9MBPS = 4,
+ RATE_INDEX_11MBPS = 5,
+ RATE_INDEX_12MBPS = 6,
+ RATE_INDEX_18MBPS = 7,
+ RATE_INDEX_22MBPS = 8,
+ RATE_INDEX_24MBPS = 9,
+ RATE_INDEX_36MBPS = 10,
+ RATE_INDEX_48MBPS = 11,
+ RATE_INDEX_54MBPS = 12,
+ RATE_INDEX_MAX = RATE_INDEX_54MBPS,
+ MAX_RATE_INDEX,
+ INVALID_RATE_INDEX = MAX_RATE_INDEX,
+ RATE_INDEX_ENUM_MAX_SIZE = 0x7FFFFFFF
+};
+
+enum {
+ RATE_MASK_1MBPS = 0x1,
+ RATE_MASK_2MBPS = 0x2,
+ RATE_MASK_5_5MBPS = 0x4,
+ RATE_MASK_11MBPS = 0x20,
+};
+
+#define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */
+#define OFDM_RATE_BIT BIT(6)
+#define PBCC_RATE_BIT BIT(7)
#
# Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
#                    and others.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This utility makes it easy to create OpenStack objects
import logging
import re
import socket
import struct

import os
import time
from keystoneauth1.exceptions import Unauthorized

from snaps.config.flavor import FlavorConfig
from snaps.config.image import ImageConfig
from snaps.config.keypair import KeypairConfig
from snaps.config.network import PortConfig, NetworkConfig
from snaps.config.project import ProjectConfig
from snaps.config.qos import QoSConfig
from snaps.config.router import RouterConfig
from snaps.config.security_group import SecurityGroupConfig
from snaps.config.user import UserConfig
from snaps.config.vm_inst import VmInstanceConfig
from snaps.config.volume import VolumeConfig
from snaps.config.volume_type import VolumeTypeConfig
from snaps.openstack.create_flavor import OpenStackFlavor
from snaps.openstack.create_image import OpenStackImage
from snaps.openstack.create_keypairs import OpenStackKeypair
from snaps.openstack.create_network import OpenStackNetwork
from snaps.openstack.create_project import OpenStackProject
from snaps.openstack.create_qos import OpenStackQoS
f
n class="kn">from snaps.provisioning import ansible_utils logger = logging.getLogger('lanuch_utils') DEFAULT_CREDS_KEY = 'admin' def launch_config(config, tmplt_file, deploy, clean, clean_image): """ Launches all objects and applies any configured ansible playbooks :param config: the environment configuration dict object :param tmplt_file: the path to the SNAPS-OO template file :param deploy: when True deploy :param clean: when True clean :param clean_image: when True clean the image when clean is True """ os_config = config.get('openstack') creators = list() vm_dict = dict() images_dict = dict() flavors_dict = dict() networks_dict = dict() routers_dict = dict() os_creds_dict = dict() if os_config: os_creds_dict = __get_creds_dict(os_config) # Create projects projects_dict = __create_instances( os_creds_dict, OpenStackProject, ProjectConfig, os_config.get('projects'), 'project', clean) creators.append(projects_dict) # Create users users_dict = __create_instances( os_creds_dict, OpenStackUser, UserConfig, os_config.get('users'), 'user', clean) creators.append(users_dict) # Associate new users to projects if not clean: for project_creator in projects_dict.values(): users = project_creator.project_settings.users for user_name in users: user_creator = users_dict.get(user_name) if user_creator: project_creator.assoc_user( user_creator.get_user()) # Create flavors flavors_dict = __create_instances( os_creds_dict, OpenStackFlavor, FlavorConfig, os_config.get('flavors'), 'flavor', clean, users_dict) creators.append(flavors_dict) # Create QoS specs qos_dict = __create_instances( os_creds_dict, OpenStackQoS, QoSConfig, os_config.get('qos_specs'), 'qos_spec', clean, users_dict) creators.append(qos_dict) # Create volume types vol_type_dict = __create_instances( os_creds_dict, OpenStackVolumeType, VolumeTypeConfig, os_config.get('volume_types'), 'volume_type', clean, users_dict) creators.append(vol_type_dict) # Create volume types vol_dict = __create_instances( os_creds_dict, OpenStackVolume, VolumeConfig, os_config.get('volumes'), 'volume', clean, users_dict) creators.append(vol_dict) # Create images images_dict = __create_instances( os_creds_dict, OpenStackImage, ImageConfig, os_config.get('images'), 'image', clean, users_dict) creators.append(images_dict) # Create networks networks_dict = __create_instances( os_creds_dict, OpenStackNetwork, NetworkConfig, os_config.get('networks'), 'network', clean, users_dict) creators.append(networks_dict) # Create routers routers_dict = __create_instances( os_creds_dict, OpenStackRouter, RouterConfig, os_config.get('routers'), 'router', clean, users_dict) creators.append(routers_dict) # Create keypairs keypairs_dict = __create_instances( os_creds_dict, OpenStackKeypair, KeypairConfig, os_config.get('keypairs'), 'keypair', clean, users_dict) creators.append(keypairs_dict) # Create security groups creators.append(__create_instances( os_creds_dict, OpenStackSecurityGroup, SecurityGroupConfig, os_config.get('security_groups'), 'security_group', clean, users_dict)) # Create instance vm_dict = __create_vm_instances( os_creds_dict, users_dict, os_config.get('instances'), images_dict, keypairs_dict, clean) creators.append(vm_dict) logger.info( 'Completed creating/retrieving all configured instances') # Must enter either block if clean: # Cleanup Environment __cleanup(creators, clean_image) elif deploy: # Provision VMs ansible_config = config.get('ansible') if ansible_config and vm_dict: if not __apply_ansible_playbooks( ansible_config, os_creds_dict, vm_dict, images_dict, flavors_dict, networks_dict, routers_dict, tmplt_file): logger.error("Problem applying ansible playbooks") def __get_creds_dict(os_conn_config): """ Returns a dict of OSCreds where the key is the creds name. For backwards compatibility, credentials not contained in a list (only one) will be returned with the key of None :param os_conn_config: the credential configuration :return: a dict of OSCreds objects """ if 'connection' in os_conn_config: return {DEFAULT_CREDS_KEY: __get_os_credentials(os_conn_config)} elif 'connections' in os_conn_config: out = dict() for os_conn_dict in os_conn_config['connections']: config = os_conn_dict.get('connection') if not config: raise Exception('Invalid connection format') name = config.get('name') if not name: raise Exception('Connection config requires a name field') out[name] = __get_os_credentials(os_conn_dict) return out def __get_creds(os_creds_dict, os_user_dict, inst_config): """ Returns the appropriate credentials :param os_creds_dict: a dictionary of OSCreds objects where the name is the key :param os_user_dict: a dictionary of OpenStackUser objects where the name is the key :param inst_config: :return: an OSCreds instance or None """ os_creds = os_creds_dict.get(DEFAULT_CREDS_KEY) if 'os_user' in inst_config: os_user_conf = inst_config['os_user'] if 'name' in os_user_conf: user_creator = os_user_dict.get(os_user_conf['name']) if user_creator: return user_creator.get_os_creds( project_name=os_user_conf.get('project_name')) elif 'os_creds_name' in inst_config: if 'os_creds_name' in inst_config: os_creds = os_creds_dict[inst_config['os_creds_name']] return os_creds def __get_os_credentials(os_conn_config): """ Returns an object containing all of the information required to access OpenStack APIs :param os_conn_config: The configuration holding the credentials :return: an OSCreds instance """ config = os_conn_config.get('connection') if not config: raise Exception('Invalid connection configuration') proxy_settings = None http_proxy = config.get('http_proxy') if http_proxy: tokens = re.split(':', http_proxy) ssh_proxy_cmd = config.get('ssh_proxy_cmd') proxy_settings = ProxySettings(host=tokens[0], port=tokens[1], ssh_proxy_cmd=ssh_proxy_cmd) else: if 'proxy_settings' in config: host = config['proxy_settings'].get('host') port = config['proxy_settings'].get('port') if host and host != 'None' and port and port != 'None': proxy_settings = ProxySettings(**config['proxy_settings']) if proxy_settings: config['proxy_settings'] = proxy_settings else: if config.get('proxy_settings'): del config['proxy_settings'] return OSCreds(**config) def __parse_ports_config(config): """ Parses the "ports" configuration :param config: The dictionary to parse :return: a list of PortConfig objects """ out = list() for port_config in config: out.append(PortConfig(**port_config.get('port'))) return out def __create_instances(os_creds_dict, creator_class, config_class, config, config_key, cleanup=False, os_users_dict=None): """ Returns a dictionary of SNAPS creator objects where the key is the name :param os_creds_dict: Dictionary of OSCreds objects where the key is the name :param config: The list of configurations for the same type :param config_key: The list of configurations for the same type :param cleanup: Denotes whether or not this is being called for cleanup :return: dictionary """ out = {} if config: for config_dict in config: inst_config = config_dict.get(config_key) if inst_config: creds = __get_creds(os_creds_dict, os_users_dict, inst_config) if creds: creator = creator_class( creds, config_class(**inst_config)) if creator: if cleanup: try: creator.initialize() except Unauthorized as e: logger.warn( 'Unable to initialize creator [%s] - %s', creator, e) else: creator.create() out[inst_config['name']] = creator logger.info('Initialized configured %ss', config_key) return out def __create_vm_instances(os_creds_dict, os_users_dict, instances_config, image_dict, keypairs_dict, cleanup=False): """ Returns a dictionary of OpenStackVmInstance objects where the key is the instance name :param os_creds_dict: Dictionary of OSCreds objects where the key is the name :param os_users_dict: Dictionary of OpenStackUser objects where the key is the username :param instances_config: The list of VM instance configurations :param image_dict: A dictionary of images that will probably be used to instantiate the VM instance :param keypairs_dict: A dictionary of keypairs that will probably be used to instantiate the VM instance :param cleanup: Denotes whether or not this is being called for cleanup :return: dictionary """ vm_dict = {} if instances_config: for instance_config in instances_config: conf = instance_config.get('instance') if conf: if image_dict: image_creator = image_dict.get(conf.get('imageName')) if image_creator: instance_settings = VmInstanceConfig( **instance_config['instance']) kp_creator = keypairs_dict.get( conf.get('keypair_name')) try: vm_dict[conf[ 'name']] = deploy_utils.create_vm_instance( __get_creds( os_creds_dict, os_users_dict, conf), instance_settings, image_creator.image_settings, keypair_creator=kp_creator, init_only=cleanup) except Unauthorized as e: if not cleanup: logger.warn('Unable to initialize VM - %s', e) raise else: raise Exception('Image creator instance not found.' ' Cannot instantiate') else: if not cleanup: raise Exception('Image dictionary is None. Cannot ' 'instantiate') else: raise Exception('Instance configuration is None. Cannot ' 'instantiate') logger.info('Created configured instances') return vm_dict def __apply_ansible_playbooks(ansible_configs, os_creds_dict, vm_dict, image_dict, flavor_dict, networks_dict, routers_dict, tmplt_file): """ Applies ansible playbooks to running VMs with floating IPs :param ansible_configs: a list of Ansible configurations :param os_creds_dict: Dictionary of OSCreds objects where the key is the name :param vm_dict: the dictionary of newly instantiated VMs where the name is the key :param image_dict: the dictionary of newly instantiated images where the name is the key :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key :param networks_dict: the dictionary of newly instantiated networks where the name is the key :param routers_dict: the dictionary of newly instantiated routers where the name is the key :param tmplt_file: the path of the SNAPS-OO template file for setting the CWD so playbook location is relative to the deployment file :return: t/f - true if successful """ logger.info("Applying Ansible Playbooks") if ansible_configs: # Set CWD so the deployment file's playbook location can leverage # relative paths orig_cwd = os.getcwd() env_dir = os.path.dirname(tmplt_file) os.chdir(env_dir) # Apply playbooks for ansible_config in ansible_configs: # Ensure all hosts are accepting SSH session requests for vm_name in ansible_config['hosts']: vm_inst = vm_dict.get(vm_name) if vm_inst: if not vm_inst.vm_ssh_active(block=True): logger.warning( 'Timeout waiting for instance to respond to ' 'SSH requests') return False os_creds = os_creds_dict.get('admin-creds') __apply_ansible_playbook( ansible_config, os_creds, vm_dict, image_dict, flavor_dict, networks_dict, routers_dict) # Return to original directory os.chdir(orig_cwd) return True def __apply_ansible_playbook(ansible_config, os_creds, vm_dict, image_dict, flavor_dict, networks_dict, routers_dict): """ Applies an Ansible configuration setting :param ansible_config: the configuration settings :param os_creds: the OpenStack admin credentials object :param vm_dict: the dictionary of newly instantiated VMs where the name is the key :param image_dict: the dictionary of newly instantiated images where the name is the key :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key :param networks_dict: the dictionary of newly instantiated networks where the name is the key :param routers_dict: the dictionary of newly instantiated routers where the name is the key """ if ansible_config: (remote_user, floating_ips, private_key_filepath, proxy_settings) = __get_connection_info( ansible_config, vm_dict) if floating_ips: for key, vm_creator in vm_dict.items(): fip = vm_creator.get_floating_ip() if fip and fip.ip in floating_ips: if not vm_creator.cloud_init_complete(block=True): raise Exception( 'Cannot apply playbooks as cloud-init has not ' 'completed') variables = __get_variables( ansible_config.get('variables'), os_creds, vm_dict, image_dict, flavor_dict, networks_dict, routers_dict) retval = ansible_utils.apply_playbook( ansible_config['playbook_location'], floating_ips, remote_user, private_key_filepath, variables=variables, proxy_setting=proxy_settings) if retval != 0: # Not a fatal type of event raise Exception( 'Error applying playbook found at location - %s', ansible_config.get('playbook_location')) elif ansible_config.get('post_processing'): post_proc_config = ansible_config['post_processing'] if 'sleep' in post_proc_config: time.sleep(post_proc_config['sleep']) if 'reboot' in post_proc_config: for vm_name in post_proc_config['reboot']: if vm_name in vm_dict: logger.info('Rebooting VM - %s', vm_name) vm_dict[vm_name].reboot() return retval def __get_connection_info(ansible_config, vm_dict): """ Returns a tuple of data required for connecting to the running VMs (remote_user, [floating_ips], private_key_filepath, proxy_settings) :param ansible_config: the configuration settings :param vm_dict: the dictionary of VMs where the VM name is the key :return: tuple where the first element is the user and the second is a list of floating IPs and the third is the private key file location and the fourth is an instance of the snaps.ProxySettings class (note: in order to work, each of the hosts need to have the same sudo_user and private key file location values) """ if ansible_config.get('hosts'): hosts = ansible_config['hosts'] if len(hosts) > 0: floating_ips = list() remote_user = None pk_file = None proxy_settings = None for host in hosts: vm = vm_dict.get(host) if vm: fip = vm.get_floating_ip() if fip: remote_user = vm.get_image_user() if fip: floating_ips.append(fip.ip) else: raise Exception( 'Could not find floating IP for VM - ' + vm.name) pk_file = vm.keypair_settings.private_filepath proxy_settings = vm.get_os_creds().proxy_settings else: logger.error('Could not locate VM with name - ' + host) return remote_user, floating_ips, pk_file, proxy_settings return None def __get_variables(var_config, os_creds, vm_dict, image_dict, flavor_dict, networks_dict, routers_dict): """ Returns a dictionary of substitution variables to be used for Ansible templates :param var_config: the variable configuration settings :param os_creds: the OpenStack admin credentials object :param vm_dict: the dictionary of newly instantiated VMs where the name is the key :param image_dict: the dictionary of newly instantiated images where the name is the key :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key :param networks_dict: the dictionary of newly instantiated networks where the name is the key :param routers_dict: the dictionary of newly instantiated routers where the name is the key :return: dictionary or None """ if var_config and vm_dict and len(vm_dict) > 0: variables = dict() for key, value in var_config.items(): value = __get_variable_value( value, os_creds, vm_dict, image_dict, flavor_dict, networks_dict, routers_dict) if key and value: variables[key] = value logger.info( "Set Jinga2 variable with key [%s] the value [%s]", key, value) else: raise Exception( 'Key - [' + str(key) + '] or Value [' + str(value) + '] must not be None') return variables return None def __get_variable_value(var_config_values, os_creds, vm_dict, image_dict, flavor_dict, networks_dict, routers_dict): """ Returns the associated variable value for use by Ansible for substitution purposes :param var_config_values: the configuration dictionary :param os_creds: the OpenStack admin credentials object :param vm_dict: the dictionary of newly instantiated VMs where the name is the key :param image_dict: the dictionary of newly instantiated images where the name is the key :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key :param networks_dict: the dictionary of newly instantiated networks where the name is the key :param routers_dict: the dictionary of newly instantiated routers where the name is the key :return: """ if var_config_values['type'] == 'string': return __get_string_variable_value(var_config_values) if var_config_values['type'] == 'vm-attr': return __get_vm_attr_variable_value(var_config_values, vm_dict) if var_config_values['type'] == 'os_creds': return __get_os_creds_variable_value(var_config_values, os_creds) if var_config_values['type'] == 'network': return __get_network_variable_value(var_config_values, networks_dict) if var_config_values['type'] == 'router': return __get_router_variable_value(var_config_values, routers_dict, os_creds) if var_config_values['type'] == 'port': return __get_vm_port_variable_value(var_config_values, vm_dict) if var_config_values['type'] == 'floating_ip': return __get_vm_fip_variable_value(var_config_values, vm_dict) if var_config_values['type'] == 'image': return __get_image_variable_value(var_config_values, image_dict) if var_config_values['type'] == 'flavor': return __get_flavor_variable_value(var_config_values, flavor_dict) return None def __get_string_variable_value(var_config_values): """ Returns the associated string value :param var_config_values: the configuration dictionary :return: the value contained in the dictionary with the key 'value' """ return var_config_values['value'] def __get_vm_attr_variable_value(var_config_values, vm_dict): """ Returns the associated value contained on a VM instance :param var_config_values: the configuration dictionary :param vm_dict: the dictionary containing all VMs where the key is the VM's name :return: the value """ vm = vm_dict.get(var_config_values['vm_name']) if vm: if var_config_values['value'] == 'floating_ip': return vm.get_floating_ip().ip if var_config_values['value'] == 'image_user': return vm.get_image_user() def __get_os_creds_variable_value(var_config_values, os_creds): """ Returns the associated OS credentials value :param var_config_values: the configuration dictionary :param os_creds: the admin OpenStack OSCreds object :return: the value """ if os_creds: if var_config_values['value'] == 'username': logger.info("Returning OS username") return os_creds.username elif var_config_values['value'] == 'password': logger.info("Returning OS password") return os_creds.password elif var_config_values['value'] == 'auth_url': logger.info("Returning OS auth_url") return os_creds.auth_url elif var_config_values['value'] == 'project_name': logger.info("Returning OS project_name") return os_creds.project_name def __get_network_variable_value(var_config_values, networks_dict): """ Returns the associated network value :param var_config_values: the configuration dictionary :param networks_dict: the dictionary containing all networks where the key is the network name :return: the value """ net_name = var_config_values.get('network_name') if net_name and networks_dict.get(net_name): network_creator = networks_dict[net_name] if 'subnet_name' in var_config_values: subnet_name = var_config_values.get('subnet_name') if subnet_name: for subnet in network_creator.get_network().subnets: if subnet_name == subnet.name: if 'value' in var_config_values: if 'gateway_ip' == var_config_values['value']: return subnet.gateway_ip if 'ip_range' == var_config_values['value']: return subnet.start + ' ' + subnet.end if 'cidr_ip' == var_config_values['value']: cidr_split = subnet.cidr.split('/') return cidr_split[0] if 'netmask' == var_config_values['value']: cidr_split = subnet.cidr.split('/') cidr_bits = 32 - int(cidr_split[1]) netmask = socket.inet_ntoa( struct.pack( '!I', (1 << 32) - (1 << cidr_bits))) return netmask if 'broadcast_ip' == var_config_values['value']: end_split = subnet.end.split('.') broadcast_ip = ( end_split[0] + '.' + end_split[1] + '.' + end_split[2] + '.255') return broadcast_ip def __get_router_variable_value(var_config_values, routers_dict, os_creds): """ Returns the associated network value :param var_config_values: the configuration dictionary :param routers_dict: the dictionary containing all networks where the key is the network name :param os_creds: the admin OpenStack credentials :return: the value """ router_name = var_config_values.get('router_name') router_creator = routers_dict[router_name] if router_creator: if 'external_fixed_ip' == var_config_values.get('attr'): neutron = neutron_utils.neutron_client(os_creds) ext_nets = neutron_utils.get_external_networks(neutron) subnet_name = var_config_values.get('subnet_name') for ext_net in ext_nets: for subnet in ext_net.subnets: if subnet_name == subnet.name: router = router_creator.get_router() for fixed_ips in router.external_fixed_ips: if subnet.id == fixed_ips['subnet_id']: return fixed_ips['ip_address'] def __get_vm_port_variable_value(var_config_values, vm_dict): """ Returns the associated OS credentials value :param var_config_values: the configuration dictionary :param vm_dict: the dictionary containing all VMs where the key is the VM's name :return: the value """ port_name = var_config_values.get('port_name') vm_name = var_config_values.get('vm_name') if port_name and vm_name: vm = vm_dict.get(vm_name) if vm: for vm_port in vm.get_vm_inst().ports: if vm_port.name == port_name: port_value_id = var_config_values.get('port_value') if port_value_id: if port_value_id == 'mac_address': return vm_port.mac_address if port_value_id == 'ip_address': return vm_port.ips[0]['ip_address'] def __get_vm_fip_variable_value(var_config_values, vm_dict): """ Returns the floating IP value if found :param var_config_values: the configuration dictionary :param vm_dict: the dictionary containing all VMs where the key is the VM's name :return: the floating IP string value or None """ fip_name = var_config_values.get('fip_name') vm_name = var_config_values.get('vm_name') if vm_name: vm = vm_dict.get(vm_name) if vm: fip = vm.get_floating_ip(fip_name) if fip: return fip.ip def __get_image_variable_value(var_config_values, image_dict): """ Returns the associated image value :param var_config_values: the configuration dictionary :param image_dict: the dictionary containing all images where the key is the name :return: the value """ if image_dict: if var_config_values.get('image_name'): image_creator = image_dict.get(var_config_values['image_name']) if image_creator: if (var_config_values.get('value') and var_config_values['value'] == 'id'): return image_creator.get_image().id if (var_config_values.get('value') and var_config_values['value'] == 'user'): return image_creator.image_settings.image_user def __get_flavor_variable_value(var_config_values, flavor_dict): """ Returns the associated flavor value :param var_config_values: the configuration dictionary :param flavor_dict: the dictionary containing all flavor creators where the key is the name :return: the value or None """ if flavor_dict: if var_config_values.get('flavor_name'): flavor_creator = flavor_dict.get(var_config_values['flavor_name']) if flavor_creator: if (var_config_values.get('value') and var_config_values['value'] == 'id'): return flavor_creator.get_flavor().id def __cleanup(creators, clean_image=False): """ Cleans up environment :param creators: the list of creators by type :param clean_image: when true :return: """ for creator_dict in reversed(creators): for key, creator in creator_dict.items(): if ((isinstance(creator, OpenStackImage) and clean_image) or not isinstance(creator, OpenStackImage)): creator.clean()