cc3000 hostdriver with the mbed socket interface

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
SolderSplashLabs
Date:
Thu Oct 03 21:02:56 2013 +0000
Revision:
24:ba3fa29197ac
Parent:
23:fed7f64dd520
Child:
25:4d4072a9cc12
Fixed comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SolderSplashLabs 23:fed7f64dd520 1 /*****************************************************************************
SolderSplashLabs 23:fed7f64dd520 2 *
SolderSplashLabs 23:fed7f64dd520 3 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
SolderSplashLabs 23:fed7f64dd520 4 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
SolderSplashLabs 23:fed7f64dd520 5 * provided help.
SolderSplashLabs 23:fed7f64dd520 6 *
SolderSplashLabs 23:fed7f64dd520 7 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus
SolderSplashLabs 23:fed7f64dd520 8 * read the following copyright:
SolderSplashLabs 23:fed7f64dd520 9 *
SolderSplashLabs 23:fed7f64dd520 10 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
SolderSplashLabs 23:fed7f64dd520 11 *
SolderSplashLabs 23:fed7f64dd520 12 * Redistribution and use in source and binary forms, with or without
SolderSplashLabs 23:fed7f64dd520 13 * modification, are permitted provided that the following conditions
SolderSplashLabs 23:fed7f64dd520 14 * are met:
SolderSplashLabs 23:fed7f64dd520 15 *
SolderSplashLabs 23:fed7f64dd520 16 * Redistributions of source code must retain the above copyright
SolderSplashLabs 23:fed7f64dd520 17 * notice, this list of conditions and the following disclaimer.
SolderSplashLabs 23:fed7f64dd520 18 *
SolderSplashLabs 23:fed7f64dd520 19 * Redistributions in binary form must reproduce the above copyright
SolderSplashLabs 23:fed7f64dd520 20 * notice, this list of conditions and the following disclaimer in the
SolderSplashLabs 23:fed7f64dd520 21 * documentation and/or other materials provided with the
SolderSplashLabs 23:fed7f64dd520 22 * distribution.
SolderSplashLabs 23:fed7f64dd520 23 *
SolderSplashLabs 23:fed7f64dd520 24 * Neither the name of Texas Instruments Incorporated nor the names of
SolderSplashLabs 23:fed7f64dd520 25 * its contributors may be used to endorse or promote products derived
SolderSplashLabs 23:fed7f64dd520 26 * from this software without specific prior written permission.
SolderSplashLabs 23:fed7f64dd520 27 *
SolderSplashLabs 23:fed7f64dd520 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
SolderSplashLabs 23:fed7f64dd520 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
SolderSplashLabs 23:fed7f64dd520 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
SolderSplashLabs 23:fed7f64dd520 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
SolderSplashLabs 23:fed7f64dd520 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SolderSplashLabs 23:fed7f64dd520 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
SolderSplashLabs 23:fed7f64dd520 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
SolderSplashLabs 23:fed7f64dd520 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
SolderSplashLabs 23:fed7f64dd520 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SolderSplashLabs 23:fed7f64dd520 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
SolderSplashLabs 23:fed7f64dd520 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SolderSplashLabs 23:fed7f64dd520 39 *
SolderSplashLabs 23:fed7f64dd520 40 *****************************************************************************/
SolderSplashLabs 23:fed7f64dd520 41 #ifndef CC3000_H
SolderSplashLabs 23:fed7f64dd520 42 #define CC3000_H
SolderSplashLabs 23:fed7f64dd520 43
SolderSplashLabs 23:fed7f64dd520 44 #include "mbed.h"
SolderSplashLabs 23:fed7f64dd520 45 #include "cc3000_common.h"
SolderSplashLabs 23:fed7f64dd520 46 #include "cc3000_spi.h"
SolderSplashLabs 23:fed7f64dd520 47 #include "cc3000_simplelink.h"
SolderSplashLabs 23:fed7f64dd520 48 #include "cc3000_netapp.h"
SolderSplashLabs 23:fed7f64dd520 49 #include "cc3000_nvmem.h"
SolderSplashLabs 23:fed7f64dd520 50 #include "cc3000_socket.h"
SolderSplashLabs 23:fed7f64dd520 51
SolderSplashLabs 23:fed7f64dd520 52 #define MAX_SOCKETS 4
SolderSplashLabs 23:fed7f64dd520 53
SolderSplashLabs 23:fed7f64dd520 54 /** Enable debug messages, comment out the ones you don't want
SolderSplashLabs 23:fed7f64dd520 55 */
SolderSplashLabs 24:ba3fa29197ac 56
SolderSplashLabs 24:ba3fa29197ac 57 // Debug - Socket interface messages
SolderSplashLabs 23:fed7f64dd520 58 #define CC3000_DEBUG_SOCKET
SolderSplashLabs 24:ba3fa29197ac 59 // Debug - HCI TX messages
SolderSplashLabs 23:fed7f64dd520 60 #define CC3000_DEBUG_HCI_TX
SolderSplashLabs 24:ba3fa29197ac 61 // Debug - HCI Rx messages
SolderSplashLabs 23:fed7f64dd520 62 #define CC3000_DEBUG_HCI_RX
SolderSplashLabs 24:ba3fa29197ac 63 // Debug - General Debug
SolderSplashLabs 23:fed7f64dd520 64 #define CC3000_DEBUG
SolderSplashLabs 23:fed7f64dd520 65
SolderSplashLabs 23:fed7f64dd520 66 // Add color too the debug messages, requires a VT100 terminal like putty, comment out to remove
SolderSplashLabs 23:fed7f64dd520 67 #define VT100_COLOUR
SolderSplashLabs 23:fed7f64dd520 68
SolderSplashLabs 23:fed7f64dd520 69 #ifdef CC3000_DEBUG_SOCKET
SolderSplashLabs 23:fed7f64dd520 70
SolderSplashLabs 23:fed7f64dd520 71 #ifdef VT100_COLOUR
SolderSplashLabs 23:fed7f64dd520 72 #define DBG_SOCKET(x, ...) std::printf("\x1b[2;32;40m[CC3000 : SOCKET] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 73 #else
SolderSplashLabs 23:fed7f64dd520 74 #define DBG_SOCKET(x, ...) std::printf("[CC3000 : SOCKET] "x"\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 75 #endif
SolderSplashLabs 23:fed7f64dd520 76
SolderSplashLabs 23:fed7f64dd520 77 #else
SolderSplashLabs 23:fed7f64dd520 78 #define DBG_SOCKET(x, ...)
SolderSplashLabs 23:fed7f64dd520 79 #endif
SolderSplashLabs 23:fed7f64dd520 80
SolderSplashLabs 23:fed7f64dd520 81 #ifdef CC3000_DEBUG_HCI_TX
SolderSplashLabs 23:fed7f64dd520 82
SolderSplashLabs 23:fed7f64dd520 83 #ifdef VT100_COLOUR
SolderSplashLabs 23:fed7f64dd520 84 #define DBG_HCI(x, ...) std::printf("\x1b[2;35;40m[CC3000 : HCI RX] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 85 #else
SolderSplashLabs 23:fed7f64dd520 86 #define DBG_HCI(x, ...) std::printf("[CC3000 : HCI RX] "x"\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 87 #endif
SolderSplashLabs 23:fed7f64dd520 88
SolderSplashLabs 23:fed7f64dd520 89 #else
SolderSplashLabs 23:fed7f64dd520 90 #define DBG_HCI(x, ...)
SolderSplashLabs 23:fed7f64dd520 91 #endif
SolderSplashLabs 23:fed7f64dd520 92
SolderSplashLabs 23:fed7f64dd520 93 #ifdef CC3000_DEBUG_HCI_RX
SolderSplashLabs 23:fed7f64dd520 94
SolderSplashLabs 23:fed7f64dd520 95 #ifdef VT100_COLOUR
SolderSplashLabs 23:fed7f64dd520 96 #define DBG_HCI_CMD(x, ...) std::printf("\x1b[2;36;40m[CC3000 : HCI TX] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 97 #else
SolderSplashLabs 23:fed7f64dd520 98 #define DBG_HCI_CMD(x, ...) std::printf("[CC3000 : HCI TX] "x"\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 99 #endif
SolderSplashLabs 23:fed7f64dd520 100
SolderSplashLabs 23:fed7f64dd520 101 #else
SolderSplashLabs 23:fed7f64dd520 102 #define DBG_HCI_CMD(x, ...)
SolderSplashLabs 23:fed7f64dd520 103 #endif
SolderSplashLabs 23:fed7f64dd520 104
SolderSplashLabs 23:fed7f64dd520 105
SolderSplashLabs 23:fed7f64dd520 106 #ifdef CC3000_DEBUG
SolderSplashLabs 23:fed7f64dd520 107
SolderSplashLabs 23:fed7f64dd520 108 #ifdef VT100_COLOUR
SolderSplashLabs 23:fed7f64dd520 109 #define DBG_CC(x, ...) std::printf("\x1b[2;32;40m[CC3000] "x"\x1b[0;37;40m\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 110 #else
SolderSplashLabs 23:fed7f64dd520 111 #define DBG_CC(x, ...) std::printf("[CC3000] "x"\r\n", ##__VA_ARGS__);
SolderSplashLabs 23:fed7f64dd520 112 #endif
SolderSplashLabs 23:fed7f64dd520 113
SolderSplashLabs 23:fed7f64dd520 114 #else
SolderSplashLabs 24:ba3fa29197ac 115 #define DBG_CC(x, ...)
SolderSplashLabs 23:fed7f64dd520 116 #endif
SolderSplashLabs 23:fed7f64dd520 117
SolderSplashLabs 23:fed7f64dd520 118 namespace mbed_cc3000 {
SolderSplashLabs 23:fed7f64dd520 119
SolderSplashLabs 23:fed7f64dd520 120 /** User info structure
SolderSplashLabs 23:fed7f64dd520 121 */
SolderSplashLabs 23:fed7f64dd520 122 typedef struct {
SolderSplashLabs 23:fed7f64dd520 123 uint8_t FTC; // First time config performed
SolderSplashLabs 23:fed7f64dd520 124 uint8_t PP_version[2]; // Patch Programmer version
SolderSplashLabs 23:fed7f64dd520 125 uint8_t SERV_PACK[2]; // Service Pack Version
SolderSplashLabs 23:fed7f64dd520 126 uint8_t DRV_VER[3]; // Driver Version
SolderSplashLabs 23:fed7f64dd520 127 uint8_t FW_VER[3]; // Firmware Version
SolderSplashLabs 23:fed7f64dd520 128 uint8_t validCIK; // CIK[] is valid (Client Interface Key)
SolderSplashLabs 23:fed7f64dd520 129 uint8_t CIK[40];
SolderSplashLabs 23:fed7f64dd520 130 } tUserFS;
SolderSplashLabs 23:fed7f64dd520 131
SolderSplashLabs 23:fed7f64dd520 132 /** Function pointers which are not yet implemented
SolderSplashLabs 23:fed7f64dd520 133 */
SolderSplashLabs 23:fed7f64dd520 134 enum FunctionNumber {
SolderSplashLabs 23:fed7f64dd520 135 FW_PATCHES = 0,
SolderSplashLabs 23:fed7f64dd520 136 DRIVER_PATCHES = 1,
SolderSplashLabs 23:fed7f64dd520 137 BOOTLOADER_PATCHES = 2,
SolderSplashLabs 23:fed7f64dd520 138 };
SolderSplashLabs 23:fed7f64dd520 139
SolderSplashLabs 23:fed7f64dd520 140 /** CC3000 Simple Link class which contains status of cc3000.
SolderSplashLabs 23:fed7f64dd520 141 */
SolderSplashLabs 23:fed7f64dd520 142 class cc3000_simple_link {
SolderSplashLabs 23:fed7f64dd520 143 public:
SolderSplashLabs 23:fed7f64dd520 144 /** ctor - sets magic number in the buffers (overflow mark).
SolderSplashLabs 23:fed7f64dd520 145 */
SolderSplashLabs 23:fed7f64dd520 146 cc3000_simple_link();
SolderSplashLabs 23:fed7f64dd520 147 /** dtor
SolderSplashLabs 23:fed7f64dd520 148 */
SolderSplashLabs 23:fed7f64dd520 149 ~cc3000_simple_link();
SolderSplashLabs 23:fed7f64dd520 150 /** Returns data received flag.
SolderSplashLabs 23:fed7f64dd520 151 * \return
SolderSplashLabs 23:fed7f64dd520 152 * if data have been received.
SolderSplashLabs 23:fed7f64dd520 153 */
SolderSplashLabs 23:fed7f64dd520 154 uint8_t get_data_received_flag();
SolderSplashLabs 23:fed7f64dd520 155 /** Set data received flag.
SolderSplashLabs 23:fed7f64dd520 156 * \param value The value to be set.
SolderSplashLabs 23:fed7f64dd520 157 */
SolderSplashLabs 23:fed7f64dd520 158 void set_data_received_flag(uint8_t value);
SolderSplashLabs 23:fed7f64dd520 159 /** Returns if tx was completed.
SolderSplashLabs 23:fed7f64dd520 160 * \return
SolderSplashLabs 23:fed7f64dd520 161 * true if tx was completed,
SolderSplashLabs 23:fed7f64dd520 162 * false otherwise.
SolderSplashLabs 23:fed7f64dd520 163 */
SolderSplashLabs 23:fed7f64dd520 164 bool get_tx_complete_signal();
SolderSplashLabs 23:fed7f64dd520 165 /**
SolderSplashLabs 23:fed7f64dd520 166 */
SolderSplashLabs 23:fed7f64dd520 167 void set_tx_complete_signal(bool value);
SolderSplashLabs 23:fed7f64dd520 168 /**
SolderSplashLabs 23:fed7f64dd520 169 */
SolderSplashLabs 23:fed7f64dd520 170 uint8_t *get_received_buffer();
SolderSplashLabs 23:fed7f64dd520 171 /**
SolderSplashLabs 23:fed7f64dd520 172 */
SolderSplashLabs 23:fed7f64dd520 173 void set_received_buffer(uint8_t value);
SolderSplashLabs 23:fed7f64dd520 174 /**
SolderSplashLabs 23:fed7f64dd520 175 */
SolderSplashLabs 23:fed7f64dd520 176 uint8_t *get_transmit_buffer();
SolderSplashLabs 23:fed7f64dd520 177 /**
SolderSplashLabs 23:fed7f64dd520 178 */
SolderSplashLabs 23:fed7f64dd520 179 void set_transmit_buffer(uint8_t value);
SolderSplashLabs 23:fed7f64dd520 180 /**
SolderSplashLabs 23:fed7f64dd520 181 */
SolderSplashLabs 23:fed7f64dd520 182 uint16_t get_number_free_buffers();
SolderSplashLabs 23:fed7f64dd520 183 /**
SolderSplashLabs 23:fed7f64dd520 184 */
SolderSplashLabs 23:fed7f64dd520 185 void set_number_free_buffers(uint16_t value);
SolderSplashLabs 23:fed7f64dd520 186 /**
SolderSplashLabs 23:fed7f64dd520 187 */
SolderSplashLabs 23:fed7f64dd520 188 uint16_t get_buffer_length();
SolderSplashLabs 23:fed7f64dd520 189 /**
SolderSplashLabs 23:fed7f64dd520 190 */
SolderSplashLabs 23:fed7f64dd520 191 void set_buffer_length(uint16_t value);
SolderSplashLabs 23:fed7f64dd520 192 /**
SolderSplashLabs 23:fed7f64dd520 193 */
SolderSplashLabs 23:fed7f64dd520 194 uint16_t get_pending_data();
SolderSplashLabs 23:fed7f64dd520 195 /**
SolderSplashLabs 23:fed7f64dd520 196 */
SolderSplashLabs 23:fed7f64dd520 197 void set_pending_data(uint16_t value);
SolderSplashLabs 23:fed7f64dd520 198 /**
SolderSplashLabs 23:fed7f64dd520 199 */
SolderSplashLabs 23:fed7f64dd520 200 uint16_t get_op_code();
SolderSplashLabs 23:fed7f64dd520 201 /**
SolderSplashLabs 23:fed7f64dd520 202 */
SolderSplashLabs 23:fed7f64dd520 203 void set_op_code(uint16_t code);
SolderSplashLabs 23:fed7f64dd520 204 /**
SolderSplashLabs 23:fed7f64dd520 205 */
SolderSplashLabs 23:fed7f64dd520 206 uint16_t get_released_packets();
SolderSplashLabs 23:fed7f64dd520 207 /**
SolderSplashLabs 23:fed7f64dd520 208 */
SolderSplashLabs 23:fed7f64dd520 209 void set_number_of_released_packets(uint16_t value);
SolderSplashLabs 23:fed7f64dd520 210 /**
SolderSplashLabs 23:fed7f64dd520 211 */
SolderSplashLabs 23:fed7f64dd520 212 uint16_t get_sent_packets();
SolderSplashLabs 23:fed7f64dd520 213 /**
SolderSplashLabs 23:fed7f64dd520 214 */
SolderSplashLabs 23:fed7f64dd520 215 void set_sent_packets(uint16_t value);
SolderSplashLabs 23:fed7f64dd520 216
SolderSplashLabs 23:fed7f64dd520 217 int32_t get_transmit_error();
SolderSplashLabs 23:fed7f64dd520 218 void set_transmit_error(int32_t value);
SolderSplashLabs 23:fed7f64dd520 219
SolderSplashLabs 23:fed7f64dd520 220 uint16_t get_buffer_size(void);
SolderSplashLabs 23:fed7f64dd520 221 void set_buffer_size(uint16_t value);
SolderSplashLabs 23:fed7f64dd520 222
SolderSplashLabs 23:fed7f64dd520 223 void *get_func_pointer(FunctionNumber function);
SolderSplashLabs 23:fed7f64dd520 224
SolderSplashLabs 23:fed7f64dd520 225 uint8_t *get_received_data(void);
SolderSplashLabs 23:fed7f64dd520 226 void set_received_data(uint8_t *pointer);
SolderSplashLabs 23:fed7f64dd520 227
SolderSplashLabs 23:fed7f64dd520 228 private:
SolderSplashLabs 23:fed7f64dd520 229 uint8_t _data_received_flag;
SolderSplashLabs 23:fed7f64dd520 230 bool _tx_complete_signal;
SolderSplashLabs 23:fed7f64dd520 231 uint16_t _rx_event_opcode;
SolderSplashLabs 23:fed7f64dd520 232 uint16_t _free_buffers;
SolderSplashLabs 23:fed7f64dd520 233 uint16_t _buffer_length;
SolderSplashLabs 23:fed7f64dd520 234 uint16_t _buffer_size;
SolderSplashLabs 23:fed7f64dd520 235 uint16_t _rx_data_pending;
SolderSplashLabs 23:fed7f64dd520 236 uint16_t _sent_packets;
SolderSplashLabs 23:fed7f64dd520 237 uint16_t _released_packets;
SolderSplashLabs 23:fed7f64dd520 238 int32_t _transmit_data_error;
SolderSplashLabs 23:fed7f64dd520 239 uint8_t *_received_data;
SolderSplashLabs 23:fed7f64dd520 240 uint8_t _rx_buffer[CC3000_RX_BUFFER_SIZE];
SolderSplashLabs 23:fed7f64dd520 241 uint8_t _tx_buffer[CC3000_TX_BUFFER_SIZE];
SolderSplashLabs 23:fed7f64dd520 242 private:
SolderSplashLabs 23:fed7f64dd520 243 int8_t *(* _fFWPatches)(uint32_t *length);
SolderSplashLabs 23:fed7f64dd520 244 int8_t *(* _fDriverPatches)(uint32_t *length);
SolderSplashLabs 23:fed7f64dd520 245 int8_t *(* _fBootLoaderPatches)(uint32_t *length);
SolderSplashLabs 23:fed7f64dd520 246 };
SolderSplashLabs 23:fed7f64dd520 247
SolderSplashLabs 23:fed7f64dd520 248 /** Forward declaration classes
SolderSplashLabs 23:fed7f64dd520 249 */
SolderSplashLabs 23:fed7f64dd520 250 class cc3000_hci;
SolderSplashLabs 23:fed7f64dd520 251 class cc3000_nvmem;
SolderSplashLabs 23:fed7f64dd520 252 class cc3000_spi;
SolderSplashLabs 23:fed7f64dd520 253 class cc3000;
SolderSplashLabs 23:fed7f64dd520 254
SolderSplashLabs 23:fed7f64dd520 255 /**
SolderSplashLabs 23:fed7f64dd520 256 */
SolderSplashLabs 23:fed7f64dd520 257 class cc3000_event {
SolderSplashLabs 23:fed7f64dd520 258 public:
SolderSplashLabs 23:fed7f64dd520 259 cc3000_event(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_spi &spi, cc3000 &cc3000);
SolderSplashLabs 23:fed7f64dd520 260 ~cc3000_event();
SolderSplashLabs 23:fed7f64dd520 261
SolderSplashLabs 23:fed7f64dd520 262 void hci_unsol_handle_patch_request(uint8_t *event_hdr);
SolderSplashLabs 23:fed7f64dd520 263 uint8_t *hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen);
SolderSplashLabs 23:fed7f64dd520 264 int32_t hci_unsol_event_handler(uint8_t *event_hdr);
SolderSplashLabs 23:fed7f64dd520 265 int32_t hci_unsolicited_event_handler(void);
SolderSplashLabs 23:fed7f64dd520 266 int32_t get_socket_active_status(int32_t sd);
SolderSplashLabs 23:fed7f64dd520 267 void set_socket_active_status(int32_t sd, int32_t status);
SolderSplashLabs 23:fed7f64dd520 268 int32_t hci_event_unsol_flowcontrol_handler(uint8_t *event);
SolderSplashLabs 23:fed7f64dd520 269 void update_socket_active_status(uint8_t *resp_params);
SolderSplashLabs 23:fed7f64dd520 270 void simplelink_wait_event(uint16_t op_code, void *ret_param);
SolderSplashLabs 23:fed7f64dd520 271 void simplelink_wait_data(uint8_t *buffer, uint8_t *from, uint8_t *fromlen);
SolderSplashLabs 23:fed7f64dd520 272
SolderSplashLabs 23:fed7f64dd520 273 void received_handler(uint8_t *buffer);
SolderSplashLabs 23:fed7f64dd520 274 private:
SolderSplashLabs 23:fed7f64dd520 275 uint32_t socket_active_status;
SolderSplashLabs 23:fed7f64dd520 276 cc3000_simple_link &_simple_link;
SolderSplashLabs 23:fed7f64dd520 277 cc3000_hci &_hci;
SolderSplashLabs 23:fed7f64dd520 278 cc3000_spi &_spi;
SolderSplashLabs 23:fed7f64dd520 279 cc3000 &_cc3000;
SolderSplashLabs 23:fed7f64dd520 280 };
SolderSplashLabs 23:fed7f64dd520 281
SolderSplashLabs 23:fed7f64dd520 282 class cc3000_netapp {
SolderSplashLabs 23:fed7f64dd520 283 public:
SolderSplashLabs 23:fed7f64dd520 284 cc3000_netapp(cc3000_simple_link &simple_link, cc3000_nvmem &nvmem, cc3000_hci &hci, cc3000_event &event);
SolderSplashLabs 23:fed7f64dd520 285 ~cc3000_netapp();
SolderSplashLabs 23:fed7f64dd520 286 int32_t config_mac_adrress(uint8_t *mac);
SolderSplashLabs 23:fed7f64dd520 287 int32_t dhcp(uint32_t *ip, uint32_t *subnet_mask,uint32_t *default_gateway, uint32_t *dns_server);
SolderSplashLabs 23:fed7f64dd520 288 #ifndef CC3000_TINY_DRIVER
SolderSplashLabs 23:fed7f64dd520 289 void ipconfig(tNetappIpconfigRetArgs *ipconfig);
SolderSplashLabs 23:fed7f64dd520 290 int32_t timeout_values(uint32_t *dhcp, uint32_t *arp,uint32_t *keep_alive, uint32_t *inactivity);
SolderSplashLabs 23:fed7f64dd520 291 int32_t ping_send(uint32_t *ip, uint32_t ping_attempts, uint32_t ping_size, uint32_t ping_timeout);
SolderSplashLabs 23:fed7f64dd520 292 void ping_report();
SolderSplashLabs 23:fed7f64dd520 293 int32_t ping_stop();
SolderSplashLabs 23:fed7f64dd520 294 int32_t arp_flush();
SolderSplashLabs 23:fed7f64dd520 295 #endif
SolderSplashLabs 23:fed7f64dd520 296 private:
SolderSplashLabs 23:fed7f64dd520 297 cc3000_simple_link &_simple_link;
SolderSplashLabs 23:fed7f64dd520 298 cc3000_nvmem &_nvmem;
SolderSplashLabs 23:fed7f64dd520 299 cc3000_hci &_hci;
SolderSplashLabs 23:fed7f64dd520 300 cc3000_event &_event;
SolderSplashLabs 23:fed7f64dd520 301 };
SolderSplashLabs 23:fed7f64dd520 302
SolderSplashLabs 23:fed7f64dd520 303 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
SolderSplashLabs 23:fed7f64dd520 304 class cc3000_security {
SolderSplashLabs 23:fed7f64dd520 305 public:
SolderSplashLabs 23:fed7f64dd520 306 void expandKey(uint8_t *expanded_key, uint8_t *key);
SolderSplashLabs 23:fed7f64dd520 307 uint8_t galois_mul2(uint8_t value);
SolderSplashLabs 23:fed7f64dd520 308 void aes_encr(uint8_t *state, uint8_t *expanded_key);
SolderSplashLabs 23:fed7f64dd520 309 void aes_decr(uint8_t *state, uint8_t *expanded_key);
SolderSplashLabs 23:fed7f64dd520 310 void aes_encrypt(uint8_t *state, uint8_t *key);
SolderSplashLabs 23:fed7f64dd520 311 void aes_decrypt(uint8_t *state, uint8_t *key);
SolderSplashLabs 23:fed7f64dd520 312 int32_t aes_read_key(uint8_t *key);
SolderSplashLabs 23:fed7f64dd520 313 int32_t aes_write_key(uint8_t *key);
SolderSplashLabs 23:fed7f64dd520 314 private:
SolderSplashLabs 23:fed7f64dd520 315 uint8_t _expanded_key[176];
SolderSplashLabs 23:fed7f64dd520 316 };
SolderSplashLabs 23:fed7f64dd520 317 #endif
SolderSplashLabs 23:fed7f64dd520 318
SolderSplashLabs 23:fed7f64dd520 319 class cc3000_socket {
SolderSplashLabs 23:fed7f64dd520 320 public:
SolderSplashLabs 23:fed7f64dd520 321 cc3000_socket(cc3000_simple_link &simplelink, cc3000_hci &hci, cc3000_event &event);
SolderSplashLabs 23:fed7f64dd520 322 ~cc3000_socket();
SolderSplashLabs 23:fed7f64dd520 323 int32_t socket(int32_t domain, int32_t type, int32_t protocol);
SolderSplashLabs 23:fed7f64dd520 324 int32_t accept(int32_t sd, sockaddr *addr, socklen_t *addrlen);
SolderSplashLabs 23:fed7f64dd520 325 int32_t bind(int32_t sd, const sockaddr *addr, int32_t addrlen);
SolderSplashLabs 23:fed7f64dd520 326 int32_t HostFlowControlConsumeBuff(int32_t sd);
SolderSplashLabs 23:fed7f64dd520 327 int32_t closesocket(int32_t sd);
SolderSplashLabs 23:fed7f64dd520 328 int32_t listen(int32_t sd, int32_t backlog);
SolderSplashLabs 23:fed7f64dd520 329 int32_t connect(int32_t sd, const sockaddr *addr, int32_t addrlen);
SolderSplashLabs 23:fed7f64dd520 330 int32_t select(int32_t nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout);
SolderSplashLabs 23:fed7f64dd520 331 int32_t getsockopt (int32_t sd, int32_t level, int32_t optname, void *optval, socklen_t *optlen);
SolderSplashLabs 23:fed7f64dd520 332 int32_t simple_link_recv(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen, int32_t opcode);
SolderSplashLabs 23:fed7f64dd520 333 int32_t simple_link_send(int32_t sd, const void *buf, int32_t len, int32_t flags, const sockaddr *to, int32_t tolen, int32_t opcode);
SolderSplashLabs 23:fed7f64dd520 334 int32_t recv(int32_t sd, void *buf, int32_t len, int32_t flags);
SolderSplashLabs 23:fed7f64dd520 335 int32_t recvfrom(int32_t sd, void *buf, int32_t len, int32_t flags, sockaddr *from, socklen_t *fromlen);
SolderSplashLabs 23:fed7f64dd520 336 int32_t send(int32_t sd, const void *buf, int32_t len, int32_t flags);
SolderSplashLabs 23:fed7f64dd520 337 int32_t sendto(int32_t sd, const void *buf, int32_t len, int32_t flags, const sockaddr *to, socklen_t tolen);
SolderSplashLabs 23:fed7f64dd520 338 int32_t mdns_advertiser(uint16_t mdns_enabled, uint8_t * device_service_name, uint16_t device_service_name_length);
SolderSplashLabs 23:fed7f64dd520 339 #ifndef CC3000_TINY_DRIVER
SolderSplashLabs 23:fed7f64dd520 340 int32_t gethostbyname(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr);
SolderSplashLabs 23:fed7f64dd520 341 int32_t setsockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen);
SolderSplashLabs 23:fed7f64dd520 342 #endif
SolderSplashLabs 23:fed7f64dd520 343 private:
SolderSplashLabs 23:fed7f64dd520 344 cc3000_simple_link &_simple_link;
SolderSplashLabs 23:fed7f64dd520 345 cc3000_hci &_hci;
SolderSplashLabs 23:fed7f64dd520 346 cc3000_event &_event;
SolderSplashLabs 23:fed7f64dd520 347 };
SolderSplashLabs 23:fed7f64dd520 348
SolderSplashLabs 23:fed7f64dd520 349 /** SPI communication class
SolderSplashLabs 23:fed7f64dd520 350 */
SolderSplashLabs 23:fed7f64dd520 351 class cc3000_spi {
SolderSplashLabs 23:fed7f64dd520 352 public:
SolderSplashLabs 23:fed7f64dd520 353 /** ctor
SolderSplashLabs 23:fed7f64dd520 354 */
SolderSplashLabs 23:fed7f64dd520 355 cc3000_spi(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, IRQn_Type irq_port, cc3000_event &event, cc3000_simple_link &simple_link);
SolderSplashLabs 23:fed7f64dd520 356 /** dtor
SolderSplashLabs 23:fed7f64dd520 357 */
SolderSplashLabs 23:fed7f64dd520 358 ~cc3000_spi();
SolderSplashLabs 23:fed7f64dd520 359 /** Close SPI - disables IRQ and set received buffer to 0
SolderSplashLabs 23:fed7f64dd520 360 * \param none
SolderSplashLabs 23:fed7f64dd520 361 * \return none
SolderSplashLabs 23:fed7f64dd520 362 */
SolderSplashLabs 23:fed7f64dd520 363 void close();
SolderSplashLabs 23:fed7f64dd520 364 /**
SolderSplashLabs 23:fed7f64dd520 365 * \param none
SolderSplashLabs 23:fed7f64dd520 366 * \return none
SolderSplashLabs 23:fed7f64dd520 367 */
SolderSplashLabs 23:fed7f64dd520 368 void open();
SolderSplashLabs 23:fed7f64dd520 369 /**
SolderSplashLabs 23:fed7f64dd520 370 * \param buffer
SolderSplashLabs 23:fed7f64dd520 371 * \param length
SolderSplashLabs 23:fed7f64dd520 372 * \return none
SolderSplashLabs 23:fed7f64dd520 373 */
SolderSplashLabs 23:fed7f64dd520 374 uint32_t first_write(uint8_t *buffer, uint16_t length);
SolderSplashLabs 23:fed7f64dd520 375 /**
SolderSplashLabs 23:fed7f64dd520 376 */
SolderSplashLabs 23:fed7f64dd520 377 uint32_t write(uint8_t *buffer, uint16_t length);
SolderSplashLabs 23:fed7f64dd520 378 /**
SolderSplashLabs 23:fed7f64dd520 379 */
SolderSplashLabs 23:fed7f64dd520 380 void write_synchronous(uint8_t *data, uint16_t size);
SolderSplashLabs 23:fed7f64dd520 381 /**
SolderSplashLabs 23:fed7f64dd520 382 */
SolderSplashLabs 23:fed7f64dd520 383 void read_synchronous(uint8_t *data, uint16_t size);
SolderSplashLabs 23:fed7f64dd520 384 /**
SolderSplashLabs 23:fed7f64dd520 385 */
SolderSplashLabs 23:fed7f64dd520 386 uint32_t read_data_cont();
SolderSplashLabs 23:fed7f64dd520 387 /**
SolderSplashLabs 23:fed7f64dd520 388 */
SolderSplashLabs 23:fed7f64dd520 389 void wlan_irq_enable();
SolderSplashLabs 23:fed7f64dd520 390 /**
SolderSplashLabs 23:fed7f64dd520 391 */
SolderSplashLabs 23:fed7f64dd520 392 void wlan_irq_disable();
SolderSplashLabs 23:fed7f64dd520 393 /**
SolderSplashLabs 23:fed7f64dd520 394 */
SolderSplashLabs 23:fed7f64dd520 395 void wlan_irq_set(uint8_t value);
SolderSplashLabs 23:fed7f64dd520 396 /**
SolderSplashLabs 23:fed7f64dd520 397 */
SolderSplashLabs 23:fed7f64dd520 398 uint32_t wlan_irq_read();
SolderSplashLabs 23:fed7f64dd520 399 /**
SolderSplashLabs 23:fed7f64dd520 400 */
SolderSplashLabs 23:fed7f64dd520 401 void WLAN_IRQHandler();
SolderSplashLabs 23:fed7f64dd520 402 /**
SolderSplashLabs 23:fed7f64dd520 403 */
SolderSplashLabs 23:fed7f64dd520 404 void write_wlan_en(uint8_t value);
SolderSplashLabs 23:fed7f64dd520 405 private:
SolderSplashLabs 23:fed7f64dd520 406 tSpiInfo _spi_info;
SolderSplashLabs 23:fed7f64dd520 407 InterruptIn _wlan_irq;
SolderSplashLabs 23:fed7f64dd520 408 DigitalOut _wlan_en;
SolderSplashLabs 23:fed7f64dd520 409 DigitalOut _wlan_cs;
SolderSplashLabs 23:fed7f64dd520 410 SPI _wlan_spi;
SolderSplashLabs 23:fed7f64dd520 411 IRQn_Type _irq_port;
SolderSplashLabs 23:fed7f64dd520 412 pFunctionPointer_t _function_pointer;
SolderSplashLabs 23:fed7f64dd520 413 cc3000_event &_event;
SolderSplashLabs 23:fed7f64dd520 414 cc3000_simple_link &_simple_link;
SolderSplashLabs 23:fed7f64dd520 415 };
SolderSplashLabs 23:fed7f64dd520 416
SolderSplashLabs 23:fed7f64dd520 417 class cc3000_hci {
SolderSplashLabs 23:fed7f64dd520 418 public:
SolderSplashLabs 23:fed7f64dd520 419 cc3000_hci(cc3000_spi &spi);
SolderSplashLabs 23:fed7f64dd520 420 ~cc3000_hci();
SolderSplashLabs 23:fed7f64dd520 421 uint16_t command_send(uint16_t op_code, uint8_t *buffer, uint8_t length);
SolderSplashLabs 23:fed7f64dd520 422 uint32_t data_send(uint8_t op_code, uint8_t *args, uint16_t arg_length,
SolderSplashLabs 23:fed7f64dd520 423 uint16_t data_length, const uint8_t *tail, uint16_t tail_length);
SolderSplashLabs 23:fed7f64dd520 424 void data_command_send(uint16_t op_code, uint8_t *buffer, uint8_t arg_length,
SolderSplashLabs 23:fed7f64dd520 425 uint16_t data_length);
SolderSplashLabs 23:fed7f64dd520 426 void patch_send(uint8_t op_code, uint8_t *buffer, uint8_t *patch, uint16_t data_length);
SolderSplashLabs 23:fed7f64dd520 427 private:
SolderSplashLabs 23:fed7f64dd520 428 cc3000_spi &_spi;
SolderSplashLabs 23:fed7f64dd520 429 };
SolderSplashLabs 23:fed7f64dd520 430
SolderSplashLabs 23:fed7f64dd520 431 class cc3000_nvmem {
SolderSplashLabs 23:fed7f64dd520 432 public:
SolderSplashLabs 23:fed7f64dd520 433 cc3000_nvmem(cc3000_hci &hci, cc3000_event &_event,cc3000_simple_link &simple_link);
SolderSplashLabs 23:fed7f64dd520 434 ~cc3000_nvmem();
SolderSplashLabs 23:fed7f64dd520 435 int32_t read(uint32_t file_id, uint32_t length, uint32_t offset, uint8_t *buff);
SolderSplashLabs 23:fed7f64dd520 436 int32_t write(uint32_t file_id, uint32_t length, uint32_t entry_offset, uint8_t *buff);
SolderSplashLabs 23:fed7f64dd520 437 uint8_t set_mac_address(uint8_t *mac);
SolderSplashLabs 23:fed7f64dd520 438 uint8_t get_mac_address(uint8_t *mac);
SolderSplashLabs 23:fed7f64dd520 439 uint8_t write_patch(uint32_t file_id, uint32_t length, const uint8_t *data);
SolderSplashLabs 23:fed7f64dd520 440 int32_t create_entry(uint32_t file_id, uint32_t new_len);
SolderSplashLabs 23:fed7f64dd520 441 #ifndef CC3000_TINY_DRIVER
SolderSplashLabs 23:fed7f64dd520 442 uint8_t read_sp_version(uint8_t* patch_ver);
SolderSplashLabs 23:fed7f64dd520 443 #endif
SolderSplashLabs 23:fed7f64dd520 444 private:
SolderSplashLabs 23:fed7f64dd520 445 cc3000_hci &_hci;
SolderSplashLabs 23:fed7f64dd520 446 cc3000_event &_event;
SolderSplashLabs 23:fed7f64dd520 447 cc3000_simple_link &_simple_link;
SolderSplashLabs 23:fed7f64dd520 448 };
SolderSplashLabs 23:fed7f64dd520 449
SolderSplashLabs 23:fed7f64dd520 450 class cc3000_wlan {
SolderSplashLabs 23:fed7f64dd520 451 public:
SolderSplashLabs 23:fed7f64dd520 452 cc3000_wlan(cc3000_simple_link &simple_link, cc3000_event &event, cc3000_spi &spi, cc3000_hci &hci);
SolderSplashLabs 23:fed7f64dd520 453 ~cc3000_wlan();
SolderSplashLabs 23:fed7f64dd520 454 /** Send SIMPLE LINK START to cc3000
SolderSplashLabs 23:fed7f64dd520 455 * \param patches_available_host Flag to indicate if patches are available
SolderSplashLabs 23:fed7f64dd520 456 * \return none
SolderSplashLabs 23:fed7f64dd520 457 */
SolderSplashLabs 23:fed7f64dd520 458 void simpleLink_init_start(uint16_t patches_available_host);
SolderSplashLabs 23:fed7f64dd520 459 /** Start wlan device. Blocking call until init is completed
SolderSplashLabs 23:fed7f64dd520 460 * \param patches_available_host Flag to indicate if patches are available
SolderSplashLabs 23:fed7f64dd520 461 * \return none
SolderSplashLabs 23:fed7f64dd520 462 */
SolderSplashLabs 23:fed7f64dd520 463 void start(uint16_t patches_available_host);
SolderSplashLabs 23:fed7f64dd520 464 /** Stop wlan device
SolderSplashLabs 23:fed7f64dd520 465 * \param none
SolderSplashLabs 23:fed7f64dd520 466 * \return none
SolderSplashLabs 23:fed7f64dd520 467 */
SolderSplashLabs 23:fed7f64dd520 468 void stop(void);
SolderSplashLabs 23:fed7f64dd520 469 #ifndef CC3000_TINY_DRIVER
SolderSplashLabs 23:fed7f64dd520 470 int32_t connect(uint32_t sec_type, const uint8_t *ssid, int32_t ssid_length, uint8_t *b_ssid, uint8_t *key, int32_t key_len);
SolderSplashLabs 23:fed7f64dd520 471 int32_t add_profile(uint32_t sec_type, uint8_t* ssid, uint32_t ssid_length, uint8_t *b_ssid, uint32_t priority, uint32_t pairwise_cipher_or_tx_key_len, uint32_t group_cipher_tx_key_index,
SolderSplashLabs 23:fed7f64dd520 472 uint32_t key_mgmt, uint8_t* pf_or_key, uint32_t pass_phrase_length);
SolderSplashLabs 23:fed7f64dd520 473 int32_t ioctl_get_scan_results(uint32_t scan_timeout, uint8_t *results);
SolderSplashLabs 23:fed7f64dd520 474 int32_t ioctl_set_scan_params(uint32_t enable, uint32_t min_dwell_time, uint32_t max_dwell_time, uint32_t num_probe_requests,
SolderSplashLabs 23:fed7f64dd520 475 uint32_t channel_mask, int32_t rssi_threshold, uint32_t snr_threshold, uint32_t default_tx_power, uint32_t *interval_list);
SolderSplashLabs 23:fed7f64dd520 476 int32_t ioctl_statusget(void);
SolderSplashLabs 23:fed7f64dd520 477 #else
SolderSplashLabs 23:fed7f64dd520 478 int32_t connect(const uint8_t *ssid, int32_t ssid_length);
SolderSplashLabs 23:fed7f64dd520 479 int32_t add_profile(uint32_t sec_type, uint8_t *ssid, uint32_t ssid_length, uint8_t *b_ssid, uint32_t priority,
SolderSplashLabs 23:fed7f64dd520 480 uint32_t pairwise_cipher_or_tx_key_len, uint32_t group_cipher_tx_key_index, uint32_t key_mgmt,
SolderSplashLabs 23:fed7f64dd520 481 uint8_t* pf_or_key, uint32_t pass_phrase_length);
SolderSplashLabs 23:fed7f64dd520 482 #endif
SolderSplashLabs 23:fed7f64dd520 483 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
SolderSplashLabs 23:fed7f64dd520 484 int32_t smart_config_process(void);
SolderSplashLabs 23:fed7f64dd520 485 #endif
SolderSplashLabs 23:fed7f64dd520 486 int32_t disconnect();
SolderSplashLabs 23:fed7f64dd520 487 int32_t ioctl_set_connection_policy(uint32_t should_connect_to_open_ap, uint32_t use_fast_connect, uint32_t use_profiles);
SolderSplashLabs 23:fed7f64dd520 488 int32_t ioctl_del_profile(uint32_t index);
SolderSplashLabs 23:fed7f64dd520 489 int32_t set_event_mask(uint32_t mask);
SolderSplashLabs 23:fed7f64dd520 490 int32_t smart_config_start(uint32_t encrypted_flag);
SolderSplashLabs 23:fed7f64dd520 491 int32_t smart_config_stop(void);
SolderSplashLabs 23:fed7f64dd520 492 int32_t smart_config_set_prefix(uint8_t *new_prefix);
SolderSplashLabs 23:fed7f64dd520 493 private:
SolderSplashLabs 23:fed7f64dd520 494 cc3000_simple_link &_simple_link;
SolderSplashLabs 23:fed7f64dd520 495 cc3000_event &_event;
SolderSplashLabs 23:fed7f64dd520 496 cc3000_spi &_spi;
SolderSplashLabs 23:fed7f64dd520 497 cc3000_hci &_hci;
SolderSplashLabs 23:fed7f64dd520 498 };
SolderSplashLabs 23:fed7f64dd520 499
SolderSplashLabs 23:fed7f64dd520 500 /** Client TCP/UDP class - TODO - not complete client
SolderSplashLabs 23:fed7f64dd520 501 */
SolderSplashLabs 23:fed7f64dd520 502 class cc3000_client {
SolderSplashLabs 23:fed7f64dd520 503 public:
SolderSplashLabs 23:fed7f64dd520 504 /**
SolderSplashLabs 23:fed7f64dd520 505 */
SolderSplashLabs 23:fed7f64dd520 506 cc3000_client(cc3000 &cc3000_ref);
SolderSplashLabs 23:fed7f64dd520 507 /**
SolderSplashLabs 23:fed7f64dd520 508 */
SolderSplashLabs 23:fed7f64dd520 509 cc3000_client(cc3000 &cc3000_ref, int16_t socket);
SolderSplashLabs 23:fed7f64dd520 510 /**
SolderSplashLabs 23:fed7f64dd520 511 */
SolderSplashLabs 23:fed7f64dd520 512 bool connected(void);
SolderSplashLabs 23:fed7f64dd520 513 /**
SolderSplashLabs 23:fed7f64dd520 514 */
SolderSplashLabs 23:fed7f64dd520 515 int16_t write(const void *buffer, uint16_t length, uint32_t flags);
SolderSplashLabs 23:fed7f64dd520 516 /**
SolderSplashLabs 23:fed7f64dd520 517 */
SolderSplashLabs 23:fed7f64dd520 518 int16_t read(void *buffer, uint16_t length, uint32_t flags);
SolderSplashLabs 23:fed7f64dd520 519 /**
SolderSplashLabs 23:fed7f64dd520 520 */
SolderSplashLabs 23:fed7f64dd520 521 void close(void);
SolderSplashLabs 23:fed7f64dd520 522
SolderSplashLabs 23:fed7f64dd520 523 private:
SolderSplashLabs 23:fed7f64dd520 524 int16_t _current_socket;
SolderSplashLabs 23:fed7f64dd520 525 cc3000 &_cc3000;
SolderSplashLabs 23:fed7f64dd520 526 };
SolderSplashLabs 23:fed7f64dd520 527
SolderSplashLabs 23:fed7f64dd520 528 /** Server TCP/UDP
SolderSplashLabs 23:fed7f64dd520 529 */
SolderSplashLabs 23:fed7f64dd520 530 class cc3000_server {
SolderSplashLabs 23:fed7f64dd520 531 public:
SolderSplashLabs 23:fed7f64dd520 532 /** ctor (server was not created successfully)
SolderSplashLabs 23:fed7f64dd520 533 */
SolderSplashLabs 23:fed7f64dd520 534 cc3000_server(cc3000 &cc3000_ref, sockaddr socket_add);
SolderSplashLabs 23:fed7f64dd520 535 /** ctor
SolderSplashLabs 23:fed7f64dd520 536 */
SolderSplashLabs 23:fed7f64dd520 537 cc3000_server(cc3000 &cc3000_ref, sockaddr socket_add, int16_t socket);
SolderSplashLabs 23:fed7f64dd520 538 /** Blocking accept
SolderSplashLabs 23:fed7f64dd520 539 */
SolderSplashLabs 23:fed7f64dd520 540 int32_t accept(void);
SolderSplashLabs 23:fed7f64dd520 541 /**
SolderSplashLabs 23:fed7f64dd520 542 */
SolderSplashLabs 23:fed7f64dd520 543 int32_t receive(void *buffer, uint16_t length, uint32_t flags);
SolderSplashLabs 23:fed7f64dd520 544 /**
SolderSplashLabs 23:fed7f64dd520 545 */
SolderSplashLabs 23:fed7f64dd520 546 int32_t send(void *buffer, uint16_t length, uint32_t flags);
SolderSplashLabs 23:fed7f64dd520 547 /**
SolderSplashLabs 23:fed7f64dd520 548 */
SolderSplashLabs 23:fed7f64dd520 549 void bind(void);
SolderSplashLabs 23:fed7f64dd520 550 /**
SolderSplashLabs 23:fed7f64dd520 551 */
SolderSplashLabs 23:fed7f64dd520 552 void listen(uint32_t backlog);
SolderSplashLabs 23:fed7f64dd520 553 /**
SolderSplashLabs 23:fed7f64dd520 554 */
SolderSplashLabs 23:fed7f64dd520 555 void close(void);
SolderSplashLabs 23:fed7f64dd520 556 private:
SolderSplashLabs 23:fed7f64dd520 557 int16_t _current_socket;
SolderSplashLabs 23:fed7f64dd520 558 sockaddr _socket_address;
SolderSplashLabs 23:fed7f64dd520 559 cc3000 &_cc3000;
SolderSplashLabs 23:fed7f64dd520 560 };
SolderSplashLabs 23:fed7f64dd520 561
SolderSplashLabs 23:fed7f64dd520 562 /** The main class of entire cc3000 implementation
SolderSplashLabs 23:fed7f64dd520 563 */
SolderSplashLabs 23:fed7f64dd520 564 class cc3000 {
SolderSplashLabs 23:fed7f64dd520 565 public:
SolderSplashLabs 23:fed7f64dd520 566 typedef struct {
SolderSplashLabs 23:fed7f64dd520 567 bool dhcp;
SolderSplashLabs 23:fed7f64dd520 568 bool connected;
SolderSplashLabs 23:fed7f64dd520 569 uint8_t socket;
SolderSplashLabs 23:fed7f64dd520 570 bool smart_config_complete;
SolderSplashLabs 23:fed7f64dd520 571 bool stop_smart_config;
SolderSplashLabs 23:fed7f64dd520 572 bool dhcp_configured;
SolderSplashLabs 23:fed7f64dd520 573 bool ok_to_shut_down;
SolderSplashLabs 23:fed7f64dd520 574 } tStatus;
SolderSplashLabs 23:fed7f64dd520 575 /** ctor for cc3000 class.
SolderSplashLabs 23:fed7f64dd520 576 * \param cc3000_irq IRQ pin
SolderSplashLabs 23:fed7f64dd520 577 * \param cc3000_en Enable pin
SolderSplashLabs 23:fed7f64dd520 578 * \param cc3000_cs Chip select pin
SolderSplashLabs 23:fed7f64dd520 579 * \param cc3000_spi SPI interface
SolderSplashLabs 23:fed7f64dd520 580 * \param irq_port IRQ pin's port
SolderSplashLabs 23:fed7f64dd520 581 */
SolderSplashLabs 23:fed7f64dd520 582 cc3000(PinName cc3000_irq, PinName cc3000_en, PinName cc3000_cs, SPI cc3000_spi, IRQn_Type irq_port);
SolderSplashLabs 23:fed7f64dd520 583 /** dtor
SolderSplashLabs 23:fed7f64dd520 584 */
SolderSplashLabs 23:fed7f64dd520 585 ~cc3000();
SolderSplashLabs 23:fed7f64dd520 586 /** Initiate cc3000. It starts the wlan communication and deletes profiles.
SolderSplashLabs 23:fed7f64dd520 587 * \param patch Patch
SolderSplashLabs 23:fed7f64dd520 588 */
SolderSplashLabs 23:fed7f64dd520 589 void start(uint8_t patch);
SolderSplashLabs 23:fed7f64dd520 590 /** Stops the wlan communication.
SolderSplashLabs 23:fed7f64dd520 591 */
SolderSplashLabs 23:fed7f64dd520 592 void stop();
SolderSplashLabs 23:fed7f64dd520 593 /** Restarts the wlan communication.
SolderSplashLabs 23:fed7f64dd520 594 */
SolderSplashLabs 23:fed7f64dd520 595 void restart(uint8_t patch);
SolderSplashLabs 23:fed7f64dd520 596 /** Disconnect wlan device
SolderSplashLabs 23:fed7f64dd520 597 *
SolderSplashLabs 23:fed7f64dd520 598 */
SolderSplashLabs 23:fed7f64dd520 599 bool disconnect(void);
SolderSplashLabs 23:fed7f64dd520 600 /** Callback which is called from the event class. This updates status of cc3000.
SolderSplashLabs 23:fed7f64dd520 601 * \param event_type Type of the event
SolderSplashLabs 23:fed7f64dd520 602 * \param data Pointer to data
SolderSplashLabs 23:fed7f64dd520 603 * \param length Length of data
SolderSplashLabs 23:fed7f64dd520 604 * \return none
SolderSplashLabs 23:fed7f64dd520 605 */
SolderSplashLabs 23:fed7f64dd520 606 void usync_callback(int32_t event_type, uint8_t *data, uint8_t length);
SolderSplashLabs 23:fed7f64dd520 607 /** Connect to SSID (open/secured) with timeout (10ms).
SolderSplashLabs 23:fed7f64dd520 608 * \param ssid SSID name
SolderSplashLabs 23:fed7f64dd520 609 * \param key Security key (if key = 0, open connection)
SolderSplashLabs 23:fed7f64dd520 610 * \param security_mode Security mode
SolderSplashLabs 23:fed7f64dd520 611 * \return true if connection was established, false otherwise.
SolderSplashLabs 23:fed7f64dd520 612 */
SolderSplashLabs 23:fed7f64dd520 613 bool connect_to_AP(const uint8_t *ssid, const uint8_t *key, int32_t security_mode);
SolderSplashLabs 23:fed7f64dd520 614 /** Connect to SSID which is secured
SolderSplashLabs 23:fed7f64dd520 615 * \param ssid SSID name
SolderSplashLabs 23:fed7f64dd520 616 * \param key Security key
SolderSplashLabs 23:fed7f64dd520 617 * \param security_mode Security mode
SolderSplashLabs 23:fed7f64dd520 618 * \return true if connection was established, false otherwise.
SolderSplashLabs 23:fed7f64dd520 619 */
SolderSplashLabs 23:fed7f64dd520 620 bool connect_secure(const uint8_t *ssid, const uint8_t *key, int32_t security_mode);
SolderSplashLabs 23:fed7f64dd520 621 /** Connect to SSID which is open (no security)
SolderSplashLabs 23:fed7f64dd520 622 * \param ssid SSID name
SolderSplashLabs 23:fed7f64dd520 623 * \return true if connection was established, false otherwise.
SolderSplashLabs 23:fed7f64dd520 624 */
SolderSplashLabs 23:fed7f64dd520 625 bool connect_open(const uint8_t *ssid);
SolderSplashLabs 23:fed7f64dd520 626 /** Status of the cc3000 connection.
SolderSplashLabs 23:fed7f64dd520 627 * \return true if it's connected, false otherwise.
SolderSplashLabs 23:fed7f64dd520 628 */
SolderSplashLabs 23:fed7f64dd520 629 bool is_connected();
SolderSplashLabs 23:fed7f64dd520 630 /** Status of DHCP.
SolderSplashLabs 23:fed7f64dd520 631 * \param none
SolderSplashLabs 23:fed7f64dd520 632 * \return true if DCHP is configured, false otherwise.
SolderSplashLabs 23:fed7f64dd520 633 */
SolderSplashLabs 23:fed7f64dd520 634 bool is_dhcp_configured();
SolderSplashLabs 23:fed7f64dd520 635 /** Status of smart confing completation.
SolderSplashLabs 23:fed7f64dd520 636 * \param none
SolderSplashLabs 23:fed7f64dd520 637 * \return smart config was set, false otherwise.
SolderSplashLabs 23:fed7f64dd520 638 */
SolderSplashLabs 23:fed7f64dd520 639 bool is_smart_confing_completed();
SolderSplashLabs 23:fed7f64dd520 640 /** Return the cc3000's mac address.
SolderSplashLabs 23:fed7f64dd520 641 * \param address Retreived mac address.
SolderSplashLabs 23:fed7f64dd520 642 * \return
SolderSplashLabs 23:fed7f64dd520 643 */
SolderSplashLabs 23:fed7f64dd520 644 uint8_t get_mac_address(uint8_t address[6]);
SolderSplashLabs 23:fed7f64dd520 645 /** Set the cc3000's mac address
SolderSplashLabs 23:fed7f64dd520 646 * \param address Mac address to be set
SolderSplashLabs 23:fed7f64dd520 647 * \return
SolderSplashLabs 23:fed7f64dd520 648 */
SolderSplashLabs 23:fed7f64dd520 649 uint8_t set_mac_address(uint8_t address[6]);
SolderSplashLabs 23:fed7f64dd520 650 /** Get user file info
SolderSplashLabs 23:fed7f64dd520 651 * \param info_file Pointer where info will be stored
SolderSplashLabs 23:fed7f64dd520 652 * \param size Available size
SolderSplashLabs 23:fed7f64dd520 653 * \return none
SolderSplashLabs 23:fed7f64dd520 654 */
SolderSplashLabs 23:fed7f64dd520 655 void get_user_file_info(uint8_t *info_file, size_t size);
SolderSplashLabs 23:fed7f64dd520 656 /** Set user filo info
SolderSplashLabs 23:fed7f64dd520 657 * \param info_file Pointer to user's info
SolderSplashLabs 23:fed7f64dd520 658 * \return none
SolderSplashLabs 23:fed7f64dd520 659 */
SolderSplashLabs 23:fed7f64dd520 660 void set_user_file_info(uint8_t *info_file, size_t size);
SolderSplashLabs 23:fed7f64dd520 661 /** Start smart config
SolderSplashLabs 23:fed7f64dd520 662 * \param smart_config_key Pointer to smart config key
SolderSplashLabs 23:fed7f64dd520 663 * \return none
SolderSplashLabs 23:fed7f64dd520 664 */
SolderSplashLabs 23:fed7f64dd520 665 void start_smart_config(const uint8_t *smart_config_key); /* TODO enable AES ? */
SolderSplashLabs 23:fed7f64dd520 666 #ifndef CC3000_TINY_DRIVER
SolderSplashLabs 23:fed7f64dd520 667 /** Return ip configuration
SolderSplashLabs 23:fed7f64dd520 668 * \param ip_config Pointer to ipconfig data
SolderSplashLabs 23:fed7f64dd520 669 * \return true if it's connected and info was retrieved, false otherwise.
SolderSplashLabs 23:fed7f64dd520 670 */
SolderSplashLabs 23:fed7f64dd520 671 bool get_ip_config(tNetappIpconfigRetArgs *ip_config);
SolderSplashLabs 23:fed7f64dd520 672 #endif
SolderSplashLabs 23:fed7f64dd520 673 /** Creates tcp client
SolderSplashLabs 23:fed7f64dd520 674 * \param ip_address Client's IP address
SolderSplashLabs 23:fed7f64dd520 675 * \param port Client's PORT
SolderSplashLabs 23:fed7f64dd520 676 * \return client with socket != -1
SolderSplashLabs 23:fed7f64dd520 677 */
SolderSplashLabs 23:fed7f64dd520 678 cc3000_client create_tcp_client(uint32_t ip_address, uint16_t port);
SolderSplashLabs 23:fed7f64dd520 679 /** Creates tcp server
SolderSplashLabs 23:fed7f64dd520 680 * \param ip_address Server's IP address
SolderSplashLabs 23:fed7f64dd520 681 * \param port Server's PORT
SolderSplashLabs 23:fed7f64dd520 682 * \return server with socket != -1
SolderSplashLabs 23:fed7f64dd520 683 */
SolderSplashLabs 23:fed7f64dd520 684 cc3000_server create_tcp_server(uint32_t ip_address, uint16_t port);
SolderSplashLabs 23:fed7f64dd520 685 /** Creates udp client
SolderSplashLabs 23:fed7f64dd520 686 * \param ip_address Server's IP address
SolderSplashLabs 23:fed7f64dd520 687 * \param port Server's PORT
SolderSplashLabs 23:fed7f64dd520 688 * \return client with socket != -1
SolderSplashLabs 23:fed7f64dd520 689 */
SolderSplashLabs 23:fed7f64dd520 690 cc3000_client create_udp_client(uint32_t ip_address, uint16_t port);
SolderSplashLabs 23:fed7f64dd520 691 /** Delete all stored profiles
SolderSplashLabs 23:fed7f64dd520 692 * \param none
SolderSplashLabs 23:fed7f64dd520 693 * \return none
SolderSplashLabs 23:fed7f64dd520 694 */
SolderSplashLabs 23:fed7f64dd520 695 void delete_profiles(void);
SolderSplashLabs 23:fed7f64dd520 696 /**
SolderSplashLabs 23:fed7f64dd520 697 *
SolderSplashLabs 23:fed7f64dd520 698 */
SolderSplashLabs 23:fed7f64dd520 699 uint32_t ping(uint32_t ip, uint8_t attempts, uint16_t timeout, uint8_t size);
SolderSplashLabs 23:fed7f64dd520 700
SolderSplashLabs 23:fed7f64dd520 701 static cc3000 *get_instance() {
SolderSplashLabs 23:fed7f64dd520 702 return _inst;
SolderSplashLabs 23:fed7f64dd520 703 }
SolderSplashLabs 23:fed7f64dd520 704 public:
SolderSplashLabs 23:fed7f64dd520 705 cc3000_simple_link _simple_link;
SolderSplashLabs 23:fed7f64dd520 706 cc3000_event _event;
SolderSplashLabs 23:fed7f64dd520 707 #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
SolderSplashLabs 23:fed7f64dd520 708 cc3000_security _security;
SolderSplashLabs 23:fed7f64dd520 709 #endif
SolderSplashLabs 23:fed7f64dd520 710 cc3000_socket _socket;
SolderSplashLabs 23:fed7f64dd520 711 cc3000_spi _spi;
SolderSplashLabs 23:fed7f64dd520 712 cc3000_hci _hci;
SolderSplashLabs 23:fed7f64dd520 713 cc3000_nvmem _nvmem;
SolderSplashLabs 23:fed7f64dd520 714 cc3000_netapp _netapp;
SolderSplashLabs 23:fed7f64dd520 715 cc3000_wlan _wlan;
SolderSplashLabs 23:fed7f64dd520 716 protected:
SolderSplashLabs 23:fed7f64dd520 717 static cc3000 *_inst;
SolderSplashLabs 23:fed7f64dd520 718 private:
SolderSplashLabs 23:fed7f64dd520 719 tStatus _status;
SolderSplashLabs 23:fed7f64dd520 720 netapp_pingreport_args_t _ping_report;
SolderSplashLabs 23:fed7f64dd520 721 bool _closed_sockets[MAX_SOCKETS];
SolderSplashLabs 23:fed7f64dd520 722 };
SolderSplashLabs 23:fed7f64dd520 723
SolderSplashLabs 23:fed7f64dd520 724 /**
SolderSplashLabs 23:fed7f64dd520 725 * Copy 32 bit to stream while converting to little endian format.
SolderSplashLabs 23:fed7f64dd520 726 * @param p pointer to the new stream
SolderSplashLabs 23:fed7f64dd520 727 * @param u32 pointer to the 32 bit
SolderSplashLabs 23:fed7f64dd520 728 * @return pointer to the new stream
SolderSplashLabs 23:fed7f64dd520 729 */
SolderSplashLabs 23:fed7f64dd520 730 uint8_t *UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32);
SolderSplashLabs 23:fed7f64dd520 731
SolderSplashLabs 23:fed7f64dd520 732 /**
SolderSplashLabs 23:fed7f64dd520 733 * Copy 16 bit to stream while converting to little endian format.
SolderSplashLabs 23:fed7f64dd520 734 * @param p pointer to the new stream
SolderSplashLabs 23:fed7f64dd520 735 * @param u32 pointer to the 16 bit
SolderSplashLabs 23:fed7f64dd520 736 * @return pointer to the new stream
SolderSplashLabs 23:fed7f64dd520 737 */
SolderSplashLabs 23:fed7f64dd520 738 uint8_t *UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16);
SolderSplashLabs 23:fed7f64dd520 739
SolderSplashLabs 23:fed7f64dd520 740 /**
SolderSplashLabs 23:fed7f64dd520 741 * Copy received stream to 16 bit in little endian format.
SolderSplashLabs 23:fed7f64dd520 742 * @param p pointer to the stream
SolderSplashLabs 23:fed7f64dd520 743 * @param offset offset in the stream
SolderSplashLabs 23:fed7f64dd520 744 * @return pointer to the new 16 bit
SolderSplashLabs 23:fed7f64dd520 745 */
SolderSplashLabs 23:fed7f64dd520 746 uint16_t STREAM_TO_UINT16_f(uint8_t* p, uint16_t offset);
SolderSplashLabs 23:fed7f64dd520 747
SolderSplashLabs 23:fed7f64dd520 748 /**
SolderSplashLabs 23:fed7f64dd520 749 * Copy received stream to 32 bit in little endian format.
SolderSplashLabs 23:fed7f64dd520 750 * @param p pointer to the stream
SolderSplashLabs 23:fed7f64dd520 751 * @param offset offset in the stream
SolderSplashLabs 23:fed7f64dd520 752 * @return pointer to the new 32 bit
SolderSplashLabs 23:fed7f64dd520 753 */
SolderSplashLabs 23:fed7f64dd520 754 uint32_t STREAM_TO_UINT32_f(uint8_t* p, uint16_t offset);
SolderSplashLabs 23:fed7f64dd520 755
SolderSplashLabs 23:fed7f64dd520 756 } /* end of mbed_cc3000 namespace */
SolderSplashLabs 23:fed7f64dd520 757
SolderSplashLabs 23:fed7f64dd520 758
SolderSplashLabs 23:fed7f64dd520 759 #endif