Driver for CC3000 Wi-Fi module

Dependencies:   NVIC_set_all_priorities

Dependents:   CC3000_Simple_Socket Wi-Go_IOT_Demo

Information

The current code has been reworked to a full object oriented application and contains an mbed socket compatible API.

CC3000 Wi-Fi module library

Info

This is the low level driver for TI's SimpleLink CC3000 device.
Port from Avnet's Wi-Go KEIL code (based on TI's CC3000 code).
Special thanks to Jim Carver from Avnet for providing the Wi-Go board and for his assistance.

Differences with TI's original code

The code functionality stays exactly the same.
In order to make it easier to use the code, following changes were made :

  • Addition of a tool to shift all IRQ priorities to a lower level since it is very important to keep the SPI handler at the highest system priority, the WLAN interrupt the second highest and all other system interrupts at a lower priority, so their handlers can be preempted by the CC3000 interrupts.
  • Addition of low level I/O controls and conditional compiler controls in cc3000_common.h.
  • CC3000 initialisation, pin declarations, SPI and WLAN irq priorities are set in Init_HostDriver , we need to call this function at the start of the main function.
  • The SPI and HCI code are joined into one file.
  • The include list has been rearranged - Only #include "wlan.h" is needed in the user API.
  • Part of the CC3000's user eeprom memory is used to store additional info (52 bytes in NVMEM_USER_FILE_1):
# bytesDescriptionInfo
1First time config parameterUseful when connecting
2Firmware updater versionused with the Firmware update tool
2Service Pack versionused with the Firmware update tool
3Driver Versionused with the Firmware update tool
3Firmware Versionused with the Firmware update tool
1CIK validation (Client Interface Key)
40CIK data (Client Interface Key)used with the exosite

Using the Library

A user API is needed to access the CC3000 functions.
Examples:

Using the library with other processors

cc3000_common.cpp loads the irq tool for all targets:
All current mbed targets are supported by this library.

#include "NVIC_set_all_priorities.h"


All low level settings that need to change are available in cc3000_common.h

//*****************************************************************************
//              PIN CONTROLS & COMPILE CONTROLS
//*****************************************************************************
// Compiler control
#define CC3000_UNENCRYPTED_SMART_CONFIG   // No encryption
//#define CC3000_TINY_DRIVER                // Driver for small memory model CPUs

//Interrupt controls
#define NVIC_ALL_IRQ        NVIC_set_all_irq_priorities(3);         // Set ALL interrupt priorities to level 3
#define NVIC_SPI_IRQ        NVIC_SetPriority(SPI0_IRQn, 0x0);       // Wi-Fi SPI interrupt must be higher priority than SysTick
#define NVIC_PORT_IRQ       NVIC_SetPriority(PORTA_IRQn, 0x1);
#define NVIC_SYSTICK_IRQ    NVIC_SetPriority(SysTick_IRQn, 0x2);    // SysTick set to lower priority than Wi-Fi SPI bus interrupt
//#define NVIC_ADC_IRQ        NVIC_SetPriority(ADC0_IRQn, 0x3);       // ADC is the lowest of all

// Wlan controls
#define WLAN_ISF_PCR        PORTA->PCR[16]
#define WLAN_ISF_ISFR       PORTA->ISFR
#define WLAN_ISF_MASK       (1<<16)

#define WLAN_ASSERT_CS      wlan_cs = 0;   //CS : active low
#define WLAN_DEASSERT_CS    wlan_cs = 1;

#define WLAN_ASSERT_EN      wlan_en = 1;   //EN : active high
#define WLAN_DEASSERT_EN    wlan_en = 0;

#define WLAN_READ_IRQ       wlan_int

#define WLAN_ENABLE_IRQ     wlan_int.fall(&WLAN_IRQHandler);
#define WLAN_DISABLE_IRQ    wlan_int.fall(NULL);

#define WLAN_IRQ_PIN_CREATE         InterruptIn wlan_int (PTA16);
#define WLAN_EN_PIN_CREATE          DigitalOut  wlan_en  (PTA13);
#define WLAN_CS_PIN_CREATE          DigitalOut  wlan_cs  (PTD0);
#define WLAN_SPI_PORT_CREATE        SPI wlan(PTD2, PTD3, PTC5); // mosi, miso, sclk

#define WLAN_SPI_PORT_INIT          wlan.format(8,1);
#define WLAN_SPI_SET_FREQ           wlan.frequency(12000000);
#define WLAN_SPI_SET_IRQ_HANDLER    wlan_int.fall(&WLAN_IRQHandler);

#define WLAN_SPI_WRITE              wlan.write(*data++);
#define WLAN_SPI_READ               wlan.write(0x03);          // !! DO NOT MODIFY the 0x03 parameter (CC3000 will not respond).

API documentation

Due to a little problem with the links on the mbed site, the API documentation is not directly accessible (will be solved in a next release).
Currently, it is only accessible by adding modules.html to the API doc link: http://mbed.org/users/frankvnk/code/CC3000_Hostdriver/docs/tip/modules.html

Committer:
frankvnk
Date:
Fri Aug 09 12:23:24 2013 +0000
Revision:
8:b48bb4df9319
Parent:
6:d733efcc2c56
Child:
10:5afa438c12fd
issue with enable/disable IRQ through wlan_int.fall - replaced with NVIC_... code.
; Additional code improvements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 0:c44f0314d6ec 1 /*****************************************************************************
frankvnk 0:c44f0314d6ec 2 *
frankvnk 0:c44f0314d6ec 3 * socket.h - CC3000 Host Driver Implementation.
frankvnk 0:c44f0314d6ec 4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
frankvnk 0:c44f0314d6ec 5 *
frankvnk 0:c44f0314d6ec 6 * Redistribution and use in source and binary forms, with or without
frankvnk 0:c44f0314d6ec 7 * modification, are permitted provided that the following conditions
frankvnk 0:c44f0314d6ec 8 * are met:
frankvnk 0:c44f0314d6ec 9 *
frankvnk 0:c44f0314d6ec 10 * Redistributions of source code must retain the above copyright
frankvnk 0:c44f0314d6ec 11 * notice, this list of conditions and the following disclaimer.
frankvnk 0:c44f0314d6ec 12 *
frankvnk 0:c44f0314d6ec 13 * Redistributions in binary form must reproduce the above copyright
frankvnk 0:c44f0314d6ec 14 * notice, this list of conditions and the following disclaimer in the
frankvnk 0:c44f0314d6ec 15 * documentation and/or other materials provided with the
frankvnk 0:c44f0314d6ec 16 * distribution.
frankvnk 0:c44f0314d6ec 17 *
frankvnk 0:c44f0314d6ec 18 * Neither the name of Texas Instruments Incorporated nor the names of
frankvnk 0:c44f0314d6ec 19 * its contributors may be used to endorse or promote products derived
frankvnk 0:c44f0314d6ec 20 * from this software without specific prior written permission.
frankvnk 0:c44f0314d6ec 21 *
frankvnk 0:c44f0314d6ec 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
frankvnk 0:c44f0314d6ec 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
frankvnk 0:c44f0314d6ec 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
frankvnk 0:c44f0314d6ec 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
frankvnk 0:c44f0314d6ec 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
frankvnk 0:c44f0314d6ec 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
frankvnk 0:c44f0314d6ec 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
frankvnk 0:c44f0314d6ec 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
frankvnk 0:c44f0314d6ec 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
frankvnk 0:c44f0314d6ec 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
frankvnk 0:c44f0314d6ec 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
frankvnk 0:c44f0314d6ec 33 *
frankvnk 0:c44f0314d6ec 34 *****************************************************************************/
frankvnk 0:c44f0314d6ec 35 #ifndef __SOCKET_H__
frankvnk 0:c44f0314d6ec 36 #define __SOCKET_H__
frankvnk 0:c44f0314d6ec 37
frankvnk 6:d733efcc2c56 38 #include "evnt_handler.h"
frankvnk 4:d8255a5aad46 39
frankvnk 5:854f9b13a0f9 40 //*****************************************************************************
frankvnk 5:854f9b13a0f9 41 //
frankvnk 5:854f9b13a0f9 42 //! \addtogroup socket
frankvnk 5:854f9b13a0f9 43 //! @{
frankvnk 5:854f9b13a0f9 44 //
frankvnk 5:854f9b13a0f9 45 //*****************************************************************************
frankvnk 5:854f9b13a0f9 46
frankvnk 0:c44f0314d6ec 47 /** CC3000 Host driver - Socket API
frankvnk 0:c44f0314d6ec 48 *
frankvnk 0:c44f0314d6ec 49 */
frankvnk 0:c44f0314d6ec 50
frankvnk 0:c44f0314d6ec 51 #ifdef __cplusplus
frankvnk 0:c44f0314d6ec 52 extern "C" {
frankvnk 0:c44f0314d6ec 53 #endif
frankvnk 0:c44f0314d6ec 54
frankvnk 8:b48bb4df9319 55 // BEWARE! When using send-non-blocking, always check the return value.
frankvnk 8:b48bb4df9319 56 // If -2, nothing was actually sent and you have to retry if you still want the data.
frankvnk 8:b48bb4df9319 57 //#define SEND_NON_BLOCKING
frankvnk 8:b48bb4df9319 58
frankvnk 4:d8255a5aad46 59 //Enable this flag if and only if you must comply with BSD socket
frankvnk 4:d8255a5aad46 60 //close() function
frankvnk 4:d8255a5aad46 61 #ifdef _API_USE_BSD_CLOSE
frankvnk 4:d8255a5aad46 62 #define close(sd) closesocket(sd)
frankvnk 4:d8255a5aad46 63 #endif
frankvnk 4:d8255a5aad46 64
frankvnk 4:d8255a5aad46 65 //Enable this flag if and only if you must comply with BSD socket read() and
frankvnk 4:d8255a5aad46 66 //write() functions
frankvnk 4:d8255a5aad46 67 #ifdef _API_USE_BSD_READ_WRITE
frankvnk 4:d8255a5aad46 68 #define read(sd, buf, len, flags) recv(sd, buf, len, flags)
frankvnk 4:d8255a5aad46 69 #define write(sd, buf, len, flags) send(sd, buf, len, flags)
frankvnk 4:d8255a5aad46 70 #endif
frankvnk 4:d8255a5aad46 71
frankvnk 4:d8255a5aad46 72 #define SOCKET_OPEN_PARAMS_LEN (12)
frankvnk 4:d8255a5aad46 73 #define SOCKET_CLOSE_PARAMS_LEN (4)
frankvnk 4:d8255a5aad46 74 #define SOCKET_ACCEPT_PARAMS_LEN (4)
frankvnk 4:d8255a5aad46 75 #define SOCKET_BIND_PARAMS_LEN (20)
frankvnk 4:d8255a5aad46 76 #define SOCKET_LISTEN_PARAMS_LEN (8)
frankvnk 4:d8255a5aad46 77 #define SOCKET_GET_HOST_BY_NAME_PARAMS_LEN (9)
frankvnk 4:d8255a5aad46 78 #define SOCKET_CONNECT_PARAMS_LEN (20)
frankvnk 4:d8255a5aad46 79 #define SOCKET_SELECT_PARAMS_LEN (44)
frankvnk 4:d8255a5aad46 80 #define SOCKET_SET_SOCK_OPT_PARAMS_LEN (20)
frankvnk 4:d8255a5aad46 81 #define SOCKET_GET_SOCK_OPT_PARAMS_LEN (12)
frankvnk 4:d8255a5aad46 82 #define SOCKET_RECV_FROM_PARAMS_LEN (12)
frankvnk 4:d8255a5aad46 83 #define SOCKET_SENDTO_PARAMS_LEN (24)
frankvnk 4:d8255a5aad46 84 #define SOCKET_MDNS_ADVERTISE_PARAMS_LEN (12)
frankvnk 4:d8255a5aad46 85
frankvnk 4:d8255a5aad46 86 //#define NULL 0
frankvnk 4:d8255a5aad46 87
frankvnk 4:d8255a5aad46 88 // The legnth of arguments for the SEND command: sd + buff_offset + len + flags,
frankvnk 4:d8255a5aad46 89 // while size of each parameter is 32 bit - so the total length is 16 bytes;
frankvnk 4:d8255a5aad46 90
frankvnk 4:d8255a5aad46 91 #define HCI_CMND_SEND_ARG_LENGTH (16)
frankvnk 4:d8255a5aad46 92 #define SELECT_TIMEOUT_MIN_MICRO_SECONDS 5000
frankvnk 4:d8255a5aad46 93 #define HEADERS_SIZE_DATA (SPI_HEADER_SIZE + 5)
frankvnk 4:d8255a5aad46 94 #define SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE (SPI_HEADER_SIZE + SIMPLE_LINK_HCI_CMND_HEADER_SIZE)
frankvnk 4:d8255a5aad46 95 #define MDNS_DEVICE_SERVICE_MAX_LENGTH (32)
frankvnk 4:d8255a5aad46 96
frankvnk 4:d8255a5aad46 97
frankvnk 0:c44f0314d6ec 98 #define HOSTNAME_MAX_LENGTH (230) // 230 bytes + header shouldn't exceed 8 bit value
frankvnk 0:c44f0314d6ec 99
frankvnk 0:c44f0314d6ec 100 //--------- Address Families --------
frankvnk 0:c44f0314d6ec 101
frankvnk 0:c44f0314d6ec 102 #define AF_INET 2
frankvnk 0:c44f0314d6ec 103 #define AF_INET6 23
frankvnk 0:c44f0314d6ec 104
frankvnk 0:c44f0314d6ec 105 //------------ Socket Types ------------
frankvnk 0:c44f0314d6ec 106
frankvnk 0:c44f0314d6ec 107 #define SOCK_STREAM 1
frankvnk 0:c44f0314d6ec 108 #define SOCK_DGRAM 2
frankvnk 0:c44f0314d6ec 109 #define SOCK_RAW 3 // Raw sockets allow new IPv4 protocols to be implemented in user space. A raw socket receives or sends the raw datagram not including link level headers
frankvnk 0:c44f0314d6ec 110 #define SOCK_RDM 4
frankvnk 0:c44f0314d6ec 111 #define SOCK_SEQPACKET 5
frankvnk 0:c44f0314d6ec 112
frankvnk 0:c44f0314d6ec 113 //----------- Socket Protocol ----------
frankvnk 0:c44f0314d6ec 114
frankvnk 0:c44f0314d6ec 115 #define IPPROTO_IP 0 // dummy for IP
frankvnk 0:c44f0314d6ec 116 #define IPPROTO_ICMP 1 // control message protocol
frankvnk 0:c44f0314d6ec 117 #define IPPROTO_IPV4 IPPROTO_IP // IP inside IP
frankvnk 0:c44f0314d6ec 118 #define IPPROTO_TCP 6 // tcp
frankvnk 0:c44f0314d6ec 119 #define IPPROTO_UDP 17 // user datagram protocol
frankvnk 0:c44f0314d6ec 120 #define IPPROTO_IPV6 41 // IPv6 in IPv6
frankvnk 0:c44f0314d6ec 121 #define IPPROTO_NONE 59 // No next header
frankvnk 0:c44f0314d6ec 122 #define IPPROTO_RAW 255 // raw IP packet
frankvnk 0:c44f0314d6ec 123 #define IPPROTO_MAX 256
frankvnk 0:c44f0314d6ec 124
frankvnk 0:c44f0314d6ec 125 //----------- Socket retunr codes -----------
frankvnk 0:c44f0314d6ec 126
frankvnk 0:c44f0314d6ec 127 #define SOC_ERROR (-1) // error
frankvnk 4:d8255a5aad46 128 #define SOC_IN_PROGRESS (-2) // socket in progress
frankvnk 0:c44f0314d6ec 129
frankvnk 0:c44f0314d6ec 130 //----------- Socket Options -----------
frankvnk 4:d8255a5aad46 131 #define SOL_SOCKET 0xffff // socket level
frankvnk 4:d8255a5aad46 132 #define SOCKOPT_RECV_TIMEOUT 1 // optname to configure recv and recvfromtimeout
frankvnk 4:d8255a5aad46 133 #define SOCKOPT_NONBLOCK 2 // accept non block mode set SOCK_ON or SOCK_OFF (default block mode )
frankvnk 0:c44f0314d6ec 134 #define SOCK_ON 0 // socket non-blocking mode is enabled
frankvnk 0:c44f0314d6ec 135 #define SOCK_OFF 1 // socket blocking mode is enabled
frankvnk 0:c44f0314d6ec 136
frankvnk 0:c44f0314d6ec 137 #define TCP_NODELAY 0x0001
frankvnk 0:c44f0314d6ec 138 #define TCP_BSDURGENT 0x7000
frankvnk 0:c44f0314d6ec 139
frankvnk 0:c44f0314d6ec 140 #define MAX_PACKET_SIZE 1500
frankvnk 0:c44f0314d6ec 141 #define MAX_LISTEN_QUEUE 4
frankvnk 0:c44f0314d6ec 142
frankvnk 0:c44f0314d6ec 143 #define IOCTL_SOCKET_EVENTMASK
frankvnk 0:c44f0314d6ec 144
frankvnk 0:c44f0314d6ec 145 #define ENOBUFS 55 // No buffer space available
frankvnk 0:c44f0314d6ec 146
frankvnk 0:c44f0314d6ec 147 #define __FD_SETSIZE 32
frankvnk 0:c44f0314d6ec 148
frankvnk 0:c44f0314d6ec 149 #define ASIC_ADDR_LEN 8
frankvnk 0:c44f0314d6ec 150
frankvnk 0:c44f0314d6ec 151 #define NO_QUERY_RECIVED -3
frankvnk 0:c44f0314d6ec 152
frankvnk 0:c44f0314d6ec 153
frankvnk 0:c44f0314d6ec 154 typedef struct _in_addr_t
frankvnk 0:c44f0314d6ec 155 {
frankvnk 0:c44f0314d6ec 156 unsigned long s_addr; // load with inet_aton()
frankvnk 0:c44f0314d6ec 157 } in_addr;
frankvnk 0:c44f0314d6ec 158
frankvnk 6:d733efcc2c56 159 /*typedef struct _sockaddr_t
frankvnk 0:c44f0314d6ec 160 {
frankvnk 4:d8255a5aad46 161 unsigned short int sa_family;
frankvnk 4:d8255a5aad46 162 unsigned char sa_data[14];
frankvnk 6:d733efcc2c56 163 } sockaddr;*/
frankvnk 0:c44f0314d6ec 164
frankvnk 0:c44f0314d6ec 165 typedef struct _sockaddr_in_t
frankvnk 0:c44f0314d6ec 166 {
frankvnk 0:c44f0314d6ec 167 short sin_family; // e.g. AF_INET
frankvnk 0:c44f0314d6ec 168 unsigned short sin_port; // e.g. htons(3490)
frankvnk 0:c44f0314d6ec 169 in_addr sin_addr; // see struct in_addr, below
frankvnk 0:c44f0314d6ec 170 char sin_zero[8]; // zero this if you want to
frankvnk 0:c44f0314d6ec 171 } sockaddr_in;
frankvnk 0:c44f0314d6ec 172
frankvnk 0:c44f0314d6ec 173 typedef unsigned long socklen_t;
frankvnk 0:c44f0314d6ec 174
frankvnk 0:c44f0314d6ec 175 // The fd_set member is required to be an array of longs.
frankvnk 0:c44f0314d6ec 176 typedef long int __fd_mask;
frankvnk 0:c44f0314d6ec 177
frankvnk 0:c44f0314d6ec 178 // It's easier to assume 8-bit bytes than to get CHAR_BIT.
frankvnk 0:c44f0314d6ec 179 #define __NFDBITS (8 * sizeof (__fd_mask))
frankvnk 0:c44f0314d6ec 180 #define __FDELT(d) ((d) / __NFDBITS)
frankvnk 0:c44f0314d6ec 181 #define __FDMASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS))
frankvnk 0:c44f0314d6ec 182
frankvnk 0:c44f0314d6ec 183 // fd_set for select and pselect.
frankvnk 0:c44f0314d6ec 184 typedef struct
frankvnk 0:c44f0314d6ec 185 {
frankvnk 0:c44f0314d6ec 186 __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
frankvnk 0:c44f0314d6ec 187 #define __FDS_BITS(set) ((set)->fds_bits)
frankvnk 0:c44f0314d6ec 188 } fd_set;
frankvnk 0:c44f0314d6ec 189
frankvnk 0:c44f0314d6ec 190 // We don't use `memset' because this would require a prototype and
frankvnk 0:c44f0314d6ec 191 // the array isn't too big.
frankvnk 0:c44f0314d6ec 192 #define __FD_ZERO(set) \
frankvnk 0:c44f0314d6ec 193 do { \
frankvnk 0:c44f0314d6ec 194 unsigned int __i; \
frankvnk 0:c44f0314d6ec 195 fd_set *__arr = (set); \
frankvnk 0:c44f0314d6ec 196 for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
frankvnk 0:c44f0314d6ec 197 __FDS_BITS (__arr)[__i] = 0; \
frankvnk 0:c44f0314d6ec 198 } while (0)
frankvnk 0:c44f0314d6ec 199 #define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d))
frankvnk 0:c44f0314d6ec 200 #define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d))
frankvnk 0:c44f0314d6ec 201 #define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d))
frankvnk 0:c44f0314d6ec 202
frankvnk 0:c44f0314d6ec 203 // Access macros for 'fd_set'.
frankvnk 0:c44f0314d6ec 204 #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
frankvnk 0:c44f0314d6ec 205 #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
frankvnk 0:c44f0314d6ec 206 #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
frankvnk 0:c44f0314d6ec 207 #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
frankvnk 0:c44f0314d6ec 208
frankvnk 0:c44f0314d6ec 209 //Use in case of Big Endian only
frankvnk 0:c44f0314d6ec 210
frankvnk 0:c44f0314d6ec 211 #define htonl(A) ((((unsigned long)(A) & 0xff000000) >> 24) | \
frankvnk 0:c44f0314d6ec 212 (((unsigned long)(A) & 0x00ff0000) >> 8) | \
frankvnk 0:c44f0314d6ec 213 (((unsigned long)(A) & 0x0000ff00) << 8) | \
frankvnk 0:c44f0314d6ec 214 (((unsigned long)(A) & 0x000000ff) << 24))
frankvnk 0:c44f0314d6ec 215
frankvnk 0:c44f0314d6ec 216 #define ntohl htonl
frankvnk 0:c44f0314d6ec 217
frankvnk 0:c44f0314d6ec 218 //Use in case of Big Endian only
frankvnk 0:c44f0314d6ec 219 #define htons(A) ((((unsigned long)(A) & 0xff00) >> 8) | \
frankvnk 0:c44f0314d6ec 220 (((unsigned long)(A) & 0x00ff) << 8))
frankvnk 0:c44f0314d6ec 221
frankvnk 0:c44f0314d6ec 222
frankvnk 0:c44f0314d6ec 223 #define ntohs htons
frankvnk 0:c44f0314d6ec 224
frankvnk 0:c44f0314d6ec 225 // mDNS port - 5353 mDNS multicast address - 224.0.0.251
frankvnk 4:d8255a5aad46 226 #define SET_mDNS_ADD(sockaddr) sockaddr.sa_data[0] = 0x14; \
frankvnk 4:d8255a5aad46 227 sockaddr.sa_data[1] = 0xe9; \
frankvnk 4:d8255a5aad46 228 sockaddr.sa_data[2] = 0xe0; \
frankvnk 4:d8255a5aad46 229 sockaddr.sa_data[3] = 0x0; \
frankvnk 4:d8255a5aad46 230 sockaddr.sa_data[4] = 0x0; \
frankvnk 4:d8255a5aad46 231 sockaddr.sa_data[5] = 0xfb;
frankvnk 0:c44f0314d6ec 232
frankvnk 0:c44f0314d6ec 233
frankvnk 0:c44f0314d6ec 234 //*****************************************************************************
frankvnk 0:c44f0314d6ec 235 //
frankvnk 0:c44f0314d6ec 236 // Prototypes for the APIs.
frankvnk 0:c44f0314d6ec 237 //
frankvnk 0:c44f0314d6ec 238 //*****************************************************************************
frankvnk 0:c44f0314d6ec 239
frankvnk 4:d8255a5aad46 240 /**
frankvnk 5:854f9b13a0f9 241 * HostFlowControlConsumeBuff.
frankvnk 5:854f9b13a0f9 242 * if SEND_NON_BLOCKING is not defined - block until a free buffer is available,\n
frankvnk 5:854f9b13a0f9 243 * otherwise return the status of the available buffers.\n
frankvnk 4:d8255a5aad46 244 * @param sd socket descriptor
frankvnk 5:854f9b13a0f9 245 * @return 0 in case there are buffers available, \n
frankvnk 5:854f9b13a0f9 246 * -1 in case of bad socket\n
frankvnk 5:854f9b13a0f9 247 * -2 if there are no free buffers present (only when SEND_NON_BLOCKING is enabled)\n
frankvnk 4:d8255a5aad46 248 */
frankvnk 4:d8255a5aad46 249 int HostFlowControlConsumeBuff(int sd);
frankvnk 4:d8255a5aad46 250
frankvnk 4:d8255a5aad46 251 /**
frankvnk 5:854f9b13a0f9 252 * create an endpoint for communication.
frankvnk 5:854f9b13a0f9 253 * The socket function creates a socket that is bound to a specific transport service provider.\n
frankvnk 5:854f9b13a0f9 254 * This function is called by the application layer to obtain a socket handle.\n
frankvnk 5:854f9b13a0f9 255 * @param domain selects the protocol family which will be used for\n
frankvnk 5:854f9b13a0f9 256 * communication. On this version only AF_INET is supported\n
frankvnk 5:854f9b13a0f9 257 * @param type specifies the communication semantics. On this version\n
frankvnk 5:854f9b13a0f9 258 * only SOCK_STREAM, SOCK_DGRAM, SOCK_RAW are supported\n
frankvnk 5:854f9b13a0f9 259 * @param protocol specifies a particular protocol to be used with the\n
frankvnk 5:854f9b13a0f9 260 * socket IPPROTO_TCP, IPPROTO_UDP or IPPROTO_RAW are supported.\n
frankvnk 5:854f9b13a0f9 261 * @return On success, socket handle that is used for consequent socket operations\n
frankvnk 5:854f9b13a0f9 262 * On error, -1 is returned.\n
frankvnk 4:d8255a5aad46 263 */
frankvnk 0:c44f0314d6ec 264 extern int socket(long domain, long type, long protocol);
frankvnk 0:c44f0314d6ec 265
frankvnk 4:d8255a5aad46 266 /**
frankvnk 4:d8255a5aad46 267 * The socket function closes a created socket.
frankvnk 4:d8255a5aad46 268 * @param sd socket handle.
frankvnk 4:d8255a5aad46 269 * @return On success, zero is returned. On error, -1 is returned.
frankvnk 4:d8255a5aad46 270 */
frankvnk 0:c44f0314d6ec 271 extern long closesocket(long sd);
frankvnk 0:c44f0314d6ec 272
frankvnk 4:d8255a5aad46 273 /**
frankvnk 5:854f9b13a0f9 274 * accept a connection on a socket.
frankvnk 5:854f9b13a0f9 275 * This function is used with connection-based socket types\n
frankvnk 5:854f9b13a0f9 276 * (SOCK_STREAM). It extracts the first connection request on the\n
frankvnk 5:854f9b13a0f9 277 * queue of pending connections, creates a new connected socket, and\n
frankvnk 5:854f9b13a0f9 278 * returns a new file descriptor referring to that socket.\n
frankvnk 5:854f9b13a0f9 279 * The newly created socket is not in the listening state.\n
frankvnk 5:854f9b13a0f9 280 * The original socket sd is unaffected by this call.\n
frankvnk 5:854f9b13a0f9 281 * The argument sd is a socket that has been created with socket(),\n
frankvnk 5:854f9b13a0f9 282 * bound to a local address with bind(), and is listening for \n
frankvnk 5:854f9b13a0f9 283 * connections after a listen(). The argument addr is a pointer \n
frankvnk 5:854f9b13a0f9 284 * to a sockaddr structure. This structure is filled in with the \n
frankvnk 5:854f9b13a0f9 285 * address of the peer socket, as known to the communications layer.\n
frankvnk 5:854f9b13a0f9 286 * The exact format of the address returned addr is determined by the \n
frankvnk 5:854f9b13a0f9 287 * socket's address family. The addrlen argument is a value-result\n
frankvnk 5:854f9b13a0f9 288 * argument: it should initially contain the size of the structure\n
frankvnk 5:854f9b13a0f9 289 * pointed to by addr, on return it will contain the actual\n
frankvnk 5:854f9b13a0f9 290 * length (in bytes) of the address returned.\n
frankvnk 5:854f9b13a0f9 291 * @param[in] sd socket descriptor (handle)\n
frankvnk 5:854f9b13a0f9 292 * @param[out] addr the argument addr is a pointer to a sockaddr structure\n
frankvnk 5:854f9b13a0f9 293 * This structure is filled in with the address of the \n
frankvnk 5:854f9b13a0f9 294 * peer socket, as known to the communications layer. \n
frankvnk 5:854f9b13a0f9 295 * determined. The exact format of the address returned \n
frankvnk 5:854f9b13a0f9 296 * addr is by the socket's address sockaddr. \n
frankvnk 5:854f9b13a0f9 297 * On this version only AF_INET is supported.\n
frankvnk 5:854f9b13a0f9 298 * This argument returns in network order.\n
frankvnk 5:854f9b13a0f9 299 * @param[out] addrlen the addrlen argument is a value-result argument: \n
frankvnk 5:854f9b13a0f9 300 * it should initially contain the size of the structure\n
frankvnk 5:854f9b13a0f9 301 * pointed to by addr.\n
frankvnk 5:854f9b13a0f9 302 * @return For socket in blocking mode:\n
frankvnk 5:854f9b13a0f9 303 * - On success, socket handle. on failure negative\n
frankvnk 5:854f9b13a0f9 304 * For socket in non-blocking mode:\n
frankvnk 5:854f9b13a0f9 305 * - On connection establishment, socket handle\n
frankvnk 5:854f9b13a0f9 306 * - On connection pending, SOC_IN_PROGRESS (-2)\n
frankvnk 5:854f9b13a0f9 307 * - On failure, SOC_ERROR (-1)\n
frankvnk 4:d8255a5aad46 308 * @sa socket ; bind ; listen
frankvnk 4:d8255a5aad46 309 */
frankvnk 0:c44f0314d6ec 310 extern long accept(long sd, sockaddr *addr, socklen_t *addrlen);
frankvnk 0:c44f0314d6ec 311
frankvnk 4:d8255a5aad46 312 /**
frankvnk 5:854f9b13a0f9 313 * assign a name to a socket.
frankvnk 5:854f9b13a0f9 314 * This function gives the socket the local address addr.\n
frankvnk 5:854f9b13a0f9 315 * addr is addrlen bytes long. Traditionally, this is called when a \n
frankvnk 5:854f9b13a0f9 316 * socket is created with socket, it exists in a name space (address \n
frankvnk 5:854f9b13a0f9 317 * family) but has no name assigned.\n
frankvnk 5:854f9b13a0f9 318 * It is necessary to assign a local address before a SOCK_STREAM\n
frankvnk 5:854f9b13a0f9 319 * socket may receive connections.\n
frankvnk 4:d8255a5aad46 320 * @param[in] sd socket descriptor (handle)
frankvnk 5:854f9b13a0f9 321 * @param[out] addr specifies the destination address. On this version\n
frankvnk 5:854f9b13a0f9 322 * only AF_INET is supported.\n
frankvnk 5:854f9b13a0f9 323 * @param[out] addrlen contains the size of the structure pointed to by addr.\n
frankvnk 5:854f9b13a0f9 324 * @return On success, zero is returned.\n
frankvnk 5:854f9b13a0f9 325 * On error, -1 is returned.\n
frankvnk 4:d8255a5aad46 326 * @sa socket ; accept ; listen
frankvnk 4:d8255a5aad46 327 */
frankvnk 0:c44f0314d6ec 328 extern long bind(long sd, const sockaddr *addr, long addrlen);
frankvnk 0:c44f0314d6ec 329
frankvnk 4:d8255a5aad46 330 /**
frankvnk 5:854f9b13a0f9 331 * listen for connections on a socket.
frankvnk 5:854f9b13a0f9 332 * The willingness to accept incoming connections and a queue\n
frankvnk 5:854f9b13a0f9 333 * limit for incoming connections are specified with listen(),\n
frankvnk 5:854f9b13a0f9 334 * and then the connections are accepted with accept.\n
frankvnk 5:854f9b13a0f9 335 * The listen() call applies only to sockets of type SOCK_STREAM\n
frankvnk 5:854f9b13a0f9 336 * The backlog parameter defines the maximum length the queue of\n
frankvnk 5:854f9b13a0f9 337 * pending connections may grow to. \n
frankvnk 4:d8255a5aad46 338 * @param[in] sd socket descriptor (handle)
frankvnk 5:854f9b13a0f9 339 * @param[in] backlog specifies the listen queue depth. On this version\n
frankvnk 5:854f9b13a0f9 340 * backlog is not supported.\n
frankvnk 5:854f9b13a0f9 341 * @return On success, zero is returned.\n
frankvnk 5:854f9b13a0f9 342 * On error, -1 is returned.\n
frankvnk 4:d8255a5aad46 343 * @sa socket ; accept ; bind
frankvnk 4:d8255a5aad46 344 * @note On this version, backlog is not supported
frankvnk 4:d8255a5aad46 345 */
frankvnk 0:c44f0314d6ec 346 extern long listen(long sd, long backlog);
frankvnk 0:c44f0314d6ec 347
frankvnk 4:d8255a5aad46 348 /**
frankvnk 5:854f9b13a0f9 349 * Get host IP by name.\n
frankvnk 5:854f9b13a0f9 350 * Obtain the IP Address of machine on network\n
frankvnk 4:d8255a5aad46 351 * @param[in] hostname host name
frankvnk 4:d8255a5aad46 352 * @param[in] usNameLen name length
frankvnk 5:854f9b13a0f9 353 * @param[out] out_ip_addr This parameter is filled in with host IP address.\n
frankvnk 5:854f9b13a0f9 354 * In case that host name is not resolved, \n
frankvnk 5:854f9b13a0f9 355 * out_ip_addr is zero.\n
frankvnk 5:854f9b13a0f9 356 * @return On success, positive is returned.\n
frankvnk 5:854f9b13a0f9 357 * On error, negative is returned by its name.\n
frankvnk 5:854f9b13a0f9 358 * @note On this version, only blocking mode is supported. Also note that\n
frankvnk 5:854f9b13a0f9 359 * The function requires DNS server to be configured prior to its usage.\n
frankvnk 4:d8255a5aad46 360 */
frankvnk 0:c44f0314d6ec 361 #ifndef CC3000_TINY_DRIVER
frankvnk 0:c44f0314d6ec 362 extern int gethostbyname(char * hostname, unsigned short usNameLen, unsigned long* out_ip_addr);
frankvnk 0:c44f0314d6ec 363 #endif
frankvnk 0:c44f0314d6ec 364
frankvnk 0:c44f0314d6ec 365
frankvnk 4:d8255a5aad46 366 /**
frankvnk 5:854f9b13a0f9 367 * initiate a connection on a socket.
frankvnk 5:854f9b13a0f9 368 * Function connects the socket referred to by the socket descriptor\n
frankvnk 5:854f9b13a0f9 369 * sd, to the address specified by addr. The addrlen argument \n
frankvnk 5:854f9b13a0f9 370 * specifies the size of addr. The format of the address in addr is \n
frankvnk 5:854f9b13a0f9 371 * determined by the address space of the socket. If it is of type \n
frankvnk 5:854f9b13a0f9 372 * SOCK_DGRAM, this call specifies the peer with which the socket is \n
frankvnk 5:854f9b13a0f9 373 * to be associated; this address is that to which datagrams are to be\n
frankvnk 5:854f9b13a0f9 374 * sent, and the only address from which datagrams are to be received. \n
frankvnk 5:854f9b13a0f9 375 * If the socket is of type SOCK_STREAM, this call attempts to make a \n
frankvnk 5:854f9b13a0f9 376 * connection to another socket. The other socket is specified by \n
frankvnk 5:854f9b13a0f9 377 * address, which is an address in the communications space of the\n
frankvnk 5:854f9b13a0f9 378 * socket. Note that the function implements only blocking behavior \n
frankvnk 5:854f9b13a0f9 379 * thus the caller will be waiting either for the connection \n
frankvnk 5:854f9b13a0f9 380 * establishment or for the connection establishment failure.\n
frankvnk 4:d8255a5aad46 381 * @param[in] sd socket descriptor (handle)
frankvnk 5:854f9b13a0f9 382 * @param[in] addr specifies the destination addr. On this version\n
frankvnk 5:854f9b13a0f9 383 * only AF_INET is supported.\n
frankvnk 4:d8255a5aad46 384 * @param[out] addrlen contains the size of the structure pointed to by addr
frankvnk 5:854f9b13a0f9 385 * @return On success, zero is returned.\n
frankvnk 5:854f9b13a0f9 386 On error, -1 is returned\n
frankvnk 4:d8255a5aad46 387 * @sa socket
frankvnk 4:d8255a5aad46 388 */
frankvnk 0:c44f0314d6ec 389 extern long connect(long sd, const sockaddr *addr, long addrlen);
frankvnk 0:c44f0314d6ec 390
frankvnk 4:d8255a5aad46 391 /**
frankvnk 5:854f9b13a0f9 392 * Monitor socket activity.
frankvnk 5:854f9b13a0f9 393 * Select allow a program to monitor multiple file descriptors,\n
frankvnk 5:854f9b13a0f9 394 * waiting until one or more of the file descriptors become \n
frankvnk 5:854f9b13a0f9 395 *"ready" for some class of I/O operation \n
frankvnk 5:854f9b13a0f9 396 * @param[in] nfds the highest-numbered file descriptor in any of the\n
frankvnk 5:854f9b13a0f9 397 * three sets, plus 1. \n
frankvnk 5:854f9b13a0f9 398 * @param[out] writesds socket descriptors list for write monitoring\n
frankvnk 5:854f9b13a0f9 399 * @param[out] readsds socket descriptors list for read monitoring\n
frankvnk 5:854f9b13a0f9 400 * @param[out] exceptsds socket descriptors list for exception monitoring\n
frankvnk 5:854f9b13a0f9 401 * @param[in] timeout is an upper bound on the amount of time elapsed\n
frankvnk 5:854f9b13a0f9 402 * before select() returns. Null means infinity \n
frankvnk 5:854f9b13a0f9 403 * timeout. The minimum timeout is 5 milliseconds,\n
frankvnk 5:854f9b13a0f9 404 * less than 5 milliseconds will be set\n
frankvnk 5:854f9b13a0f9 405 * automatically to 5 milliseconds.\n
frankvnk 5:854f9b13a0f9 406 * @return On success, select() returns the number of file descriptors\n
frankvnk 5:854f9b13a0f9 407 * contained in the three returned descriptor sets (that is, the\n
frankvnk 5:854f9b13a0f9 408 * total number of bits that are set in readfds, writefds,\n
frankvnk 5:854f9b13a0f9 409 * exceptfds) which may be zero if the timeout expires before\n
frankvnk 5:854f9b13a0f9 410 * anything interesting happens.\n
frankvnk 5:854f9b13a0f9 411 * On error, -1 is returned.\n
frankvnk 5:854f9b13a0f9 412 * *readsds - return the sockets on which Read request will\n
frankvnk 5:854f9b13a0f9 413 * return without delay with valid data.\n
frankvnk 5:854f9b13a0f9 414 * *writesds - return the sockets on which Write request \n
frankvnk 5:854f9b13a0f9 415 * will return without delay.\n
frankvnk 5:854f9b13a0f9 416 * *exceptsds - return the sockets which closed recently.\n
frankvnk 5:854f9b13a0f9 417 * @Note If the timeout value set to less than 5ms it will automatically\n
frankvnk 5:854f9b13a0f9 418 * change to 5ms to prevent overload of the system\n
frankvnk 4:d8255a5aad46 419 * @sa socket
frankvnk 4:d8255a5aad46 420 */
frankvnk 4:d8255a5aad46 421 extern int select(long nfds, fd_set *readsds, fd_set *writesds, fd_set *exceptsds, struct timeval *timeout);
frankvnk 0:c44f0314d6ec 422
frankvnk 4:d8255a5aad46 423 /**
frankvnk 5:854f9b13a0f9 424 * set socket options.
frankvnk 5:854f9b13a0f9 425 * This function manipulate the options associated with a socket.\n
frankvnk 5:854f9b13a0f9 426 * Options may exist at multiple protocol levels; they are always\n
frankvnk 5:854f9b13a0f9 427 * present at the uppermost socket level.\n
frankvnk 5:854f9b13a0f9 428 * When manipulating socket options the level at which the option \n
frankvnk 5:854f9b13a0f9 429 * resides and the name of the option must be specified.\n
frankvnk 5:854f9b13a0f9 430 * To manipulate options at the socket level, level is specified as\n
frankvnk 5:854f9b13a0f9 431 * SOL_SOCKET. To manipulate options at any other level the protocol \n
frankvnk 5:854f9b13a0f9 432 * number of the appropriate protocol controlling the option is \n
frankvnk 5:854f9b13a0f9 433 * supplied. For example, to indicate that an option is to be \n
frankvnk 5:854f9b13a0f9 434 * interpreted by the TCP protocol, level should be set to the \n
frankvnk 5:854f9b13a0f9 435 * protocol number of TCP; \n
frankvnk 5:854f9b13a0f9 436 * The parameters optval and optlen are used to access optval - \n
frankvnk 5:854f9b13a0f9 437 * use for setsockopt(). For getsockopt() they identify a buffer\n
frankvnk 5:854f9b13a0f9 438 * in which the value for the requested option(s) are to \n
frankvnk 5:854f9b13a0f9 439 * be returned. For getsockopt(), optlen is a value-result \n
frankvnk 5:854f9b13a0f9 440 * parameter, initially containing the size of the buffer \n
frankvnk 5:854f9b13a0f9 441 * pointed to by option_value, and modified on return to \n
frankvnk 5:854f9b13a0f9 442 * indicate the actual size of the value returned. If no option \n
frankvnk 5:854f9b13a0f9 443 * value is to be supplied or returned, option_value may be NULL.\n
frankvnk 4:d8255a5aad46 444 * @param[in] sd socket handle
frankvnk 4:d8255a5aad46 445 * @param[in] level defines the protocol level for this option
frankvnk 4:d8255a5aad46 446 * @param[in] optname defines the option name to Interrogate
frankvnk 4:d8255a5aad46 447 * @param[in] optval specifies a value for the option
frankvnk 4:d8255a5aad46 448 * @param[in] optlen specifies the length of the option value
frankvnk 5:854f9b13a0f9 449 * @return On success, zero is returned.\n
frankvnk 5:854f9b13a0f9 450 On error, -1 is returned\n
frankvnk 4:d8255a5aad46 451 *
frankvnk 5:854f9b13a0f9 452 * @Note On this version the following two socket options are enabled:\n
frankvnk 5:854f9b13a0f9 453 * The only protocol level supported in this version is SOL_SOCKET (level).\n
frankvnk 5:854f9b13a0f9 454 * 1. SOCKOPT_RECV_TIMEOUT (optname)\n
frankvnk 5:854f9b13a0f9 455 * SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout in milliseconds.\n
frankvnk 5:854f9b13a0f9 456 * In that case optval should be pointer to unsigned long.\n
frankvnk 5:854f9b13a0f9 457 * 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on or off.\n
frankvnk 5:854f9b13a0f9 458 * In that case optval should be SOCK_ON or SOCK_OFF (optval).\n
frankvnk 4:d8255a5aad46 459 * @sa getsockopt
frankvnk 4:d8255a5aad46 460 */
frankvnk 0:c44f0314d6ec 461 #ifndef CC3000_TINY_DRIVER
frankvnk 4:d8255a5aad46 462 extern int setsockopt(long sd, long level, long optname, const void *optval, socklen_t optlen);
frankvnk 0:c44f0314d6ec 463 #endif
frankvnk 0:c44f0314d6ec 464
frankvnk 4:d8255a5aad46 465 /**
frankvnk 5:854f9b13a0f9 466 * get socket options.
frankvnk 5:854f9b13a0f9 467 * This function manipulate the options associated with a socket.\n
frankvnk 5:854f9b13a0f9 468 * Options may exist at multiple protocol levels; they are always\n
frankvnk 5:854f9b13a0f9 469 * present at the uppermost socket level.\n
frankvnk 5:854f9b13a0f9 470 * When manipulating socket options the level at which the option \n
frankvnk 5:854f9b13a0f9 471 * resides and the name of the option must be specified. \n
frankvnk 5:854f9b13a0f9 472 * To manipulate options at the socket level, level is specified as \n
frankvnk 5:854f9b13a0f9 473 * SOL_SOCKET. To manipulate options at any other level the protocol \n
frankvnk 5:854f9b13a0f9 474 * number of the appropriate protocol controlling the option is \n
frankvnk 5:854f9b13a0f9 475 * supplied. For example, to indicate that an option is to be \n
frankvnk 5:854f9b13a0f9 476 * interpreted by the TCP protocol, level should be set to the \n
frankvnk 5:854f9b13a0f9 477 * protocol number of TCP; \n
frankvnk 5:854f9b13a0f9 478 * The parameters optval and optlen are used to access optval -\n
frankvnk 5:854f9b13a0f9 479 * use for setsockopt(). For getsockopt() they identify a buffer\n
frankvnk 5:854f9b13a0f9 480 * in which the value for the requested option(s) are to \n
frankvnk 5:854f9b13a0f9 481 * be returned. For getsockopt(), optlen is a value-result \n
frankvnk 5:854f9b13a0f9 482 * parameter, initially containing the size of the buffer \n
frankvnk 5:854f9b13a0f9 483 * pointed to by option_value, and modified on return to \n
frankvnk 5:854f9b13a0f9 484 * indicate the actual size of the value returned. If no option \n
frankvnk 5:854f9b13a0f9 485 * value is to be supplied or returned, option_value may be NULL.\n
frankvnk 4:d8255a5aad46 486 * @param[in] sd socket handle
frankvnk 4:d8255a5aad46 487 * @param[in] level defines the protocol level for this option
frankvnk 4:d8255a5aad46 488 * @param[in] optname defines the option name to Interrogate
frankvnk 4:d8255a5aad46 489 * @param[out] optval specifies a value for the option
frankvnk 4:d8255a5aad46 490 * @param[out] optlen specifies the length of the option value
frankvnk 4:d8255a5aad46 491 * @return On success, zero is returned. On error, -1 is returned
frankvnk 4:d8255a5aad46 492 *
frankvnk 5:854f9b13a0f9 493 * @Note On this version the following two socket options are enabled:\n
frankvnk 5:854f9b13a0f9 494 * The only protocol level supported in this version is SOL_SOCKET (level).\n
frankvnk 5:854f9b13a0f9 495 * 1. SOCKOPT_RECV_TIMEOUT (optname)\n
frankvnk 5:854f9b13a0f9 496 * SOCKOPT_RECV_TIMEOUT configures recv and recvfrom timeout in milliseconds.\n
frankvnk 5:854f9b13a0f9 497 * In that case optval should be pointer to unsigned long.\n
frankvnk 5:854f9b13a0f9 498 * 2. SOCKOPT_NONBLOCK (optname). sets the socket non-blocking mode on or off.\n
frankvnk 5:854f9b13a0f9 499 * In that case optval should be SOCK_ON or SOCK_OFF (optval).\n
frankvnk 4:d8255a5aad46 500 * @sa setsockopt
frankvnk 4:d8255a5aad46 501 */
frankvnk 4:d8255a5aad46 502 extern int getsockopt(long sd, long level, long optname, void *optval, socklen_t *optlen);
frankvnk 4:d8255a5aad46 503
frankvnk 4:d8255a5aad46 504 /**
frankvnk 5:854f9b13a0f9 505 * Read data from socket (simple_link_recv).
frankvnk 5:854f9b13a0f9 506 * Return the length of the message on successful completion.\n
frankvnk 5:854f9b13a0f9 507 * If a message is too long to fit in the supplied buffer, excess bytes may\n
frankvnk 5:854f9b13a0f9 508 * be discarded depending on the type of socket the message is received from.\n
frankvnk 4:d8255a5aad46 509 * @param sd socket handle
frankvnk 4:d8255a5aad46 510 * @param buf read buffer
frankvnk 4:d8255a5aad46 511 * @param len buffer length
frankvnk 4:d8255a5aad46 512 * @param flags indicates blocking or non-blocking operation
frankvnk 4:d8255a5aad46 513 * @param from pointer to an address structure indicating source address
frankvnk 4:d8255a5aad46 514 * @param fromlen source address structure size
frankvnk 4:d8255a5aad46 515 * @return Return the number of bytes received, or -1 if an error occurred
frankvnk 4:d8255a5aad46 516 */
frankvnk 4:d8255a5aad46 517 int simple_link_recv(long sd, void *buf, long len, long flags, sockaddr *from, socklen_t *fromlen, long opcode);
frankvnk 4:d8255a5aad46 518
frankvnk 4:d8255a5aad46 519 /**
frankvnk 5:854f9b13a0f9 520 * Receive a message from a connection-mode socket.
frankvnk 4:d8255a5aad46 521 * @param[in] sd socket handle
frankvnk 4:d8255a5aad46 522 * @param[out] buf Points to the buffer where the message should be stored
frankvnk 5:854f9b13a0f9 523 * @param[in] len Specifies the length in bytes of the buffer pointed to \n
frankvnk 5:854f9b13a0f9 524 * by the buffer argument.\n
frankvnk 5:854f9b13a0f9 525 * @param[in] flags Specifies the type of message reception. \n
frankvnk 5:854f9b13a0f9 526 * On this version, this parameter is not supported.\n
frankvnk 4:d8255a5aad46 527 * @return Return the number of bytes received, or -1 if an error occurred
frankvnk 4:d8255a5aad46 528 * @sa recvfrom
frankvnk 4:d8255a5aad46 529 * @Note On this version, only blocking mode is supported.
frankvnk 4:d8255a5aad46 530 */
frankvnk 0:c44f0314d6ec 531 extern int recv(long sd, void *buf, long len, long flags);
frankvnk 0:c44f0314d6ec 532
frankvnk 4:d8255a5aad46 533 /**
frankvnk 5:854f9b13a0f9 534 * read data from socket (recvfrom).
frankvnk 5:854f9b13a0f9 535 * Receives a message from a connection-mode or connectionless-mode socket.\n
frankvnk 5:854f9b13a0f9 536 * Note that raw sockets are not supported.\n
frankvnk 4:d8255a5aad46 537 * @param[in] sd socket handle
frankvnk 4:d8255a5aad46 538 * @param[out] buf Points to the buffer where the message should be stored
frankvnk 5:854f9b13a0f9 539 * @param[in] len Specifies the length in bytes of the buffer pointed to \n
frankvnk 5:854f9b13a0f9 540 * by the buffer argument.\n
frankvnk 5:854f9b13a0f9 541 * @param[in] flags Specifies the type of message reception.\n
frankvnk 5:854f9b13a0f9 542 * On this version, this parameter is not supported.\n
frankvnk 5:854f9b13a0f9 543 * @param[in] from pointer to an address structure indicating the source\n
frankvnk 5:854f9b13a0f9 544 * address: sockaddr. On this version only AF_INET is\n
frankvnk 5:854f9b13a0f9 545 * supported.\n
frankvnk 4:d8255a5aad46 546 * @param[in] fromlen source address structure size
frankvnk 4:d8255a5aad46 547 * @return Return the number of bytes received, or -1 if an error occurred
frankvnk 4:d8255a5aad46 548 * @sa recv
frankvnk 4:d8255a5aad46 549 * @Note On this version, only blocking mode is supported.
frankvnk 4:d8255a5aad46 550 */
frankvnk 4:d8255a5aad46 551 extern int recvfrom(long sd, void *buf, long len, long flags, sockaddr *from, socklen_t *fromlen);
frankvnk 0:c44f0314d6ec 552
frankvnk 4:d8255a5aad46 553 /**
frankvnk 5:854f9b13a0f9 554 * Transmit a message to another socket (simple_link_send).
frankvnk 4:d8255a5aad46 555 * @param sd socket handle
frankvnk 4:d8255a5aad46 556 * @param buf write buffer
frankvnk 4:d8255a5aad46 557 * @param len buffer length
frankvnk 4:d8255a5aad46 558 * @param flags On this version, this parameter is not supported
frankvnk 4:d8255a5aad46 559 * @param to pointer to an address structure indicating destination address
frankvnk 4:d8255a5aad46 560 * @param tolen destination address structure size
frankvnk 5:854f9b13a0f9 561 * @return Return the number of bytes transmitted, or -1 if an error\n
frankvnk 5:854f9b13a0f9 562 * occurred, or -2 in case there are no free buffers available\n
frankvnk 5:854f9b13a0f9 563 * (only when SEND_NON_BLOCKING is enabled)\n
frankvnk 4:d8255a5aad46 564 */
frankvnk 4:d8255a5aad46 565 int simple_link_send(long sd, const void *buf, long len, long flags, const sockaddr *to, long tolen, long opcode);
frankvnk 0:c44f0314d6ec 566
frankvnk 4:d8255a5aad46 567 /**
frankvnk 4:d8255a5aad46 568 * Transmit a message to another socket (send).
frankvnk 4:d8255a5aad46 569 * @param sd socket handle
frankvnk 4:d8255a5aad46 570 * @param buf Points to a buffer containing the message to be sent
frankvnk 4:d8255a5aad46 571 * @param len message size in bytes
frankvnk 4:d8255a5aad46 572 * @param flags On this version, this parameter is not supported
frankvnk 5:854f9b13a0f9 573 * @return Return the number of bytes transmitted, or -1 if an\n
frankvnk 5:854f9b13a0f9 574 * error occurred\n
frankvnk 4:d8255a5aad46 575 * @Note On this version, only blocking mode is supported.
frankvnk 4:d8255a5aad46 576 * @sa sendto
frankvnk 4:d8255a5aad46 577 */
frankvnk 0:c44f0314d6ec 578 extern int send(long sd, const void *buf, long len, long flags);
frankvnk 0:c44f0314d6ec 579
frankvnk 4:d8255a5aad46 580 /**
frankvnk 4:d8255a5aad46 581 * Transmit a message to another socket (sendto).
frankvnk 4:d8255a5aad46 582 * @param sd socket handle
frankvnk 4:d8255a5aad46 583 * @param buf Points to a buffer containing the message to be sent
frankvnk 4:d8255a5aad46 584 * @param len message size in bytes
frankvnk 4:d8255a5aad46 585 * @param flags On this version, this parameter is not supported
frankvnk 5:854f9b13a0f9 586 * @param to pointer to an address structure indicating the destination\n
frankvnk 5:854f9b13a0f9 587 * address: sockaddr. On this version only AF_INET is\n
frankvnk 5:854f9b13a0f9 588 * supported.\n
frankvnk 4:d8255a5aad46 589 * @param tolen destination address structure size
frankvnk 4:d8255a5aad46 590 * @return Return the number of bytes transmitted, or -1 if an error occurred
frankvnk 4:d8255a5aad46 591 * @Note On this version, only blocking mode is supported.
frankvnk 4:d8255a5aad46 592 * @sa send
frankvnk 4:d8255a5aad46 593 */
frankvnk 4:d8255a5aad46 594 extern int sendto(long sd, const void *buf, long len, long flags, const sockaddr *to, socklen_t tolen);
frankvnk 0:c44f0314d6ec 595
frankvnk 4:d8255a5aad46 596 /**
frankvnk 4:d8255a5aad46 597 * Set CC3000 in mDNS advertiser mode in order to advertise itself.
frankvnk 4:d8255a5aad46 598 * @param[in] mdnsEnabled flag to enable/disable the mDNS feature
frankvnk 5:854f9b13a0f9 599 * @param[in] deviceServiceName Service name as part of the published\n
frankvnk 5:854f9b13a0f9 600 * canonical domain name\n
frankvnk 4:d8255a5aad46 601 * @param[in] deviceServiceNameLength Length of the service name
frankvnk 5:854f9b13a0f9 602 * @return On success, zero is returned,\n
frankvnk 5:854f9b13a0f9 603 * return SOC_ERROR if socket was not opened successfully, or if an error occurred.\n
frankvnk 4:d8255a5aad46 604 */
frankvnk 0:c44f0314d6ec 605 extern int mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength);
frankvnk 0:c44f0314d6ec 606
frankvnk 0:c44f0314d6ec 607
frankvnk 0:c44f0314d6ec 608 #ifdef __cplusplus
frankvnk 0:c44f0314d6ec 609 }
frankvnk 0:c44f0314d6ec 610 #endif // __cplusplus
frankvnk 0:c44f0314d6ec 611
frankvnk 5:854f9b13a0f9 612 //*****************************************************************************
frankvnk 5:854f9b13a0f9 613 //
frankvnk 5:854f9b13a0f9 614 // Close the Doxygen group.
frankvnk 5:854f9b13a0f9 615 //! @}
frankvnk 5:854f9b13a0f9 616 //
frankvnk 5:854f9b13a0f9 617 //*****************************************************************************
frankvnk 5:854f9b13a0f9 618
frankvnk 0:c44f0314d6ec 619 #endif // __SOCKET_H__
frankvnk 0:c44f0314d6ec 620
frankvnk 0:c44f0314d6ec 621
frankvnk 6:d733efcc2c56 622
frankvnk 6:d733efcc2c56 623
frankvnk 6:d733efcc2c56 624