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