Frank Vannieuwkerke / cc3000_hostdriver_mbedsocket

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3000_common.h Source File

cc3000_common.h

00001 /*****************************************************************************
00002 *
00003 *  C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
00004 *  Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
00005 *  provided help.
00006 *
00007 *  This version of "host driver" uses CC3000 Host Driver Implementation. Thus
00008 *  read the following copyright:
00009 *
00010 *  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
00011 *
00012 *  Redistribution and use in source and binary forms, with or without
00013 *  modification, are permitted provided that the following conditions
00014 *  are met:
00015 *
00016 *    Redistributions of source code must retain the above copyright
00017 *    notice, this list of conditions and the following disclaimer.
00018 *
00019 *    Redistributions in binary form must reproduce the above copyright
00020 *    notice, this list of conditions and the following disclaimer in the
00021 *    documentation and/or other materials provided with the
00022 *    distribution.
00023 *
00024 *    Neither the name of Texas Instruments Incorporated nor the names of
00025 *    its contributors may be used to endorse or promote products derived
00026 *    from this software without specific prior written permission.
00027 *
00028 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 *
00040 *****************************************************************************/
00041 #ifndef CC3000_COMMON_H
00042 #define CC3000_COMMON_H
00043 
00044 #include <errno.h>
00045 
00046 //#define CC3000_TINY_DRIVER                // Driver for small memory model CPUs
00047 
00048 #define ESUCCESS        0
00049 #define EFAIL          -1
00050 #define EERROR          EFAIL
00051 
00052 #define CC3000_UNENCRYPTED_SMART_CONFIG   // No encryption
00053 
00054 #define ERROR_SOCKET_INACTIVE   -57
00055 
00056 #define HCI_CC_PAYLOAD_LEN      5
00057 
00058 #define WLAN_ENABLE            (1)
00059 #define WLAN_DISABLE           (0)
00060 
00061 #define MAC_ADDR_LEN           (6)
00062 
00063 
00064 /*Defines for minimal and maximal RX buffer size. This size includes the spi
00065   header and hci header.
00066   maximal buffer size: MTU + HCI header + SPI header + sendto() args size
00067   minimum buffer size: HCI header + SPI header + max args size
00068 
00069   This buffer is used for receiving events and data.
00070   The packet can not be longer than MTU size and CC3000 does not support
00071   fragmentation. Note that the same buffer is used for reception of the data
00072   and events from CC3000. That is why the minimum is defined.
00073   The calculation for the actual size of buffer for reception is:
00074   Given the maximal data size MAX_DATA that is expected to be received by
00075   application, the required buffer Using recv() or recvfrom():
00076 
00077     max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen + ucArgsize + 1)
00078 
00079   Using gethostbyname() with minimal buffer size will limit the host name returned to 99 bytes.
00080   The 1 is used for the overrun detection
00081 */
00082 
00083 
00084 /*Defines for minimal and maximal TX buffer size.
00085   This buffer is used for sending events and data.
00086   The packet can not be longer than MTU size and CC3000 does not support
00087   fragmentation. Note that the same buffer is used for transmission of the data
00088   and commands. That is why the minimum is defined.
00089   The calculation for the actual size of buffer for transmission is:
00090   Given the maximal data size MAX_DATA, the required buffer is:
00091   Using Sendto():
00092 
00093    max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
00094    + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
00095 
00096   Using Send():
00097 
00098    max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
00099    + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
00100 
00101   The 1 is used for the overrun detection */
00102 
00103 #ifndef CC3000_TINY_DRIVER
00104     #define SP_PORTION_SIZE         512
00105 //TINY DRIVER: We use smaller buffers in order to minimize RAM consumption
00106 #else
00107     #define SP_PORTION_SIZE         32
00108 #endif
00109 
00110 
00111 //Copy 8 bit to stream while converting to little endian format.
00112 #define UINT8_TO_STREAM(_p, _val)    {*(_p)++ = (_val);}
00113 //Copy 16 bit to stream while converting to little endian format.
00114 #define UINT16_TO_STREAM(_p, _u16)    (UINT16_TO_STREAM_f(_p, _u16))
00115 //Copy 32 bit to stream while converting to little endian format.
00116 #define UINT32_TO_STREAM(_p, _u32)    (UINT32_TO_STREAM_f(_p, _u32))
00117 //Copy a specified value length bits (l) to stream while converting to little endian format.
00118 #define ARRAY_TO_STREAM(p, a, l)     {uint32_t _i; for (_i = 0; _i < l; _i++) *(p)++ = ((uint8_t *) a)[_i];}
00119 //Copy received stream to 8 bit in little endian format.
00120 #define STREAM_TO_UINT8(_p, _offset, _u8)    {_u8 = (uint8_t)(*(_p + _offset));}
00121 //Copy received stream to 16 bit in little endian format.
00122 #define STREAM_TO_UINT16(_p, _offset, _u16)    {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
00123 //Copy received stream to 32 bit in little endian format.
00124 #define STREAM_TO_UINT32(_p, _offset, _u32)    {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
00125 #define STREAM_TO_STREAM(p, a, l)     {uint32_t _i; for (_i = 0; _i < l; _i++) *(a)++= ((uint8_t *) p)[_i];}
00126 
00127 typedef struct _sockaddr_t
00128 {
00129     uint16_t  family;
00130     uint8_t   data[14];
00131 } sockaddr;
00132 
00133 struct timeval
00134 {
00135     int32_t tv_sec;       /* seconds */
00136     int32_t tv_usec;      /* microseconds */
00137 };
00138 
00139 #define SMART_CONFIG_PROFILE_SIZE        67        // 67 = 32 (max ssid) + 32 (max key) + 1 (SSID length) + 1 (security type) + 1 (key length)
00140 
00141 /* patches type */
00142 #define PATCHES_HOST_TYPE_WLAN_DRIVER   0x01
00143 #define PATCHES_HOST_TYPE_WLAN_FW       0x02
00144 #define PATCHES_HOST_TYPE_BOOTLOADER    0x03
00145 
00146 #define SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE    (16)
00147 #define SL_SIMPLE_CONFIG_PREFIX_LENGTH           (3)
00148 #define ETH_ALEN                                 (6)
00149 #define MAXIMAL_SSID_LENGTH                      (32)
00150 
00151 #define SL_PATCHES_REQUEST_DEFAULT               (0)
00152 #define SL_PATCHES_REQUEST_FORCE_HOST            (1)
00153 #define SL_PATCHES_REQUEST_FORCE_NONE            (2)
00154 
00155 
00156 #define      WLAN_SEC_UNSEC  (0)
00157 #define      WLAN_SEC_WEP    (1)
00158 #define      WLAN_SEC_WPA    (2)
00159 #define      WLAN_SEC_WPA2   (3)
00160 
00161 
00162 #define WLAN_SL_INIT_START_PARAMS_LEN           (1)
00163 #define WLAN_PATCH_PARAMS_LENGTH                (8)
00164 #define WLAN_SET_CONNECTION_POLICY_PARAMS_LEN   (12)
00165 #define WLAN_DEL_PROFILE_PARAMS_LEN             (4)
00166 #define WLAN_SET_MASK_PARAMS_LEN                (4)
00167 #define WLAN_SET_SCAN_PARAMS_LEN                (100)
00168 #define WLAN_GET_SCAN_RESULTS_PARAMS_LEN        (4)
00169 #define WLAN_ADD_PROFILE_NOSEC_PARAM_LEN        (24)
00170 #define WLAN_ADD_PROFILE_WEP_PARAM_LEN          (36)
00171 #define WLAN_ADD_PROFILE_WPA_PARAM_LEN          (44)
00172 #define WLAN_CONNECT_PARAM_LEN                  (29)
00173 #define WLAN_SMART_CONFIG_START_PARAMS_LEN      (4)
00174 
00175 #endif