Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
features/net/network-socket/nsapi_types.h@0:6c56fb4bc5f0, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:27:58 2016 +0000
- Revision:
- 0:6c56fb4bc5f0
Moving to library for sharing updates
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nexpaq | 0:6c56fb4bc5f0 | 1 | /* nsapi.h - The network socket API |
| nexpaq | 0:6c56fb4bc5f0 | 2 | * Copyright (c) 2015 ARM Limited |
| nexpaq | 0:6c56fb4bc5f0 | 3 | * |
| nexpaq | 0:6c56fb4bc5f0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| nexpaq | 0:6c56fb4bc5f0 | 5 | * you may not use this file except in compliance with the License. |
| nexpaq | 0:6c56fb4bc5f0 | 6 | * You may obtain a copy of the License at |
| nexpaq | 0:6c56fb4bc5f0 | 7 | * |
| nexpaq | 0:6c56fb4bc5f0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| nexpaq | 0:6c56fb4bc5f0 | 9 | * |
| nexpaq | 0:6c56fb4bc5f0 | 10 | * Unless required by applicable law or agreed to in writing, software |
| nexpaq | 0:6c56fb4bc5f0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| nexpaq | 0:6c56fb4bc5f0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| nexpaq | 0:6c56fb4bc5f0 | 13 | * See the License for the specific language governing permissions and |
| nexpaq | 0:6c56fb4bc5f0 | 14 | * limitations under the License. |
| nexpaq | 0:6c56fb4bc5f0 | 15 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 16 | |
| nexpaq | 0:6c56fb4bc5f0 | 17 | #ifndef NSAPI_TYPES_H |
| nexpaq | 0:6c56fb4bc5f0 | 18 | #define NSAPI_TYPES_H |
| nexpaq | 0:6c56fb4bc5f0 | 19 | |
| nexpaq | 0:6c56fb4bc5f0 | 20 | #include <stdint.h> |
| nexpaq | 0:6c56fb4bc5f0 | 21 | |
| nexpaq | 0:6c56fb4bc5f0 | 22 | #ifdef __cplusplus |
| nexpaq | 0:6c56fb4bc5f0 | 23 | extern "C" { |
| nexpaq | 0:6c56fb4bc5f0 | 24 | #endif |
| nexpaq | 0:6c56fb4bc5f0 | 25 | |
| nexpaq | 0:6c56fb4bc5f0 | 26 | |
| nexpaq | 0:6c56fb4bc5f0 | 27 | /** Enum of standardized error codes |
| nexpaq | 0:6c56fb4bc5f0 | 28 | * |
| nexpaq | 0:6c56fb4bc5f0 | 29 | * Valid error codes have negative values and may |
| nexpaq | 0:6c56fb4bc5f0 | 30 | * be returned by any network operation. |
| nexpaq | 0:6c56fb4bc5f0 | 31 | * |
| nexpaq | 0:6c56fb4bc5f0 | 32 | * @enum nsapi_error_t |
| nexpaq | 0:6c56fb4bc5f0 | 33 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 34 | typedef enum nsapi_error { |
| nexpaq | 0:6c56fb4bc5f0 | 35 | NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */ |
| nexpaq | 0:6c56fb4bc5f0 | 36 | NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */ |
| nexpaq | 0:6c56fb4bc5f0 | 37 | NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */ |
| nexpaq | 0:6c56fb4bc5f0 | 38 | NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */ |
| nexpaq | 0:6c56fb4bc5f0 | 39 | NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */ |
| nexpaq | 0:6c56fb4bc5f0 | 40 | NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */ |
| nexpaq | 0:6c56fb4bc5f0 | 41 | NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */ |
| nexpaq | 0:6c56fb4bc5f0 | 42 | NSAPI_ERROR_DNS_FAILURE = -3008, /*!< DNS failed to complete successfully */ |
| nexpaq | 0:6c56fb4bc5f0 | 43 | NSAPI_ERROR_DHCP_FAILURE = -3009, /*!< DHCP failed to complete successfully */ |
| nexpaq | 0:6c56fb4bc5f0 | 44 | NSAPI_ERROR_AUTH_FAILURE = -3010, /*!< connection to access point faield */ |
| nexpaq | 0:6c56fb4bc5f0 | 45 | NSAPI_ERROR_DEVICE_ERROR = -3011, /*!< failure interfacing with the network procesor */ |
| nexpaq | 0:6c56fb4bc5f0 | 46 | } nsapi_error_t; |
| nexpaq | 0:6c56fb4bc5f0 | 47 | |
| nexpaq | 0:6c56fb4bc5f0 | 48 | |
| nexpaq | 0:6c56fb4bc5f0 | 49 | /** Maximum size of IP address representation |
| nexpaq | 0:6c56fb4bc5f0 | 50 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 51 | #define NSAPI_IP_SIZE NSAPI_IPv6_SIZE |
| nexpaq | 0:6c56fb4bc5f0 | 52 | |
| nexpaq | 0:6c56fb4bc5f0 | 53 | /** Maximum number of bytes for IP address |
| nexpaq | 0:6c56fb4bc5f0 | 54 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 55 | #define NSAPI_IP_BYTES NSAPI_IPv6_BYTES |
| nexpaq | 0:6c56fb4bc5f0 | 56 | |
| nexpaq | 0:6c56fb4bc5f0 | 57 | /** Maximum size of MAC address representation |
| nexpaq | 0:6c56fb4bc5f0 | 58 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 59 | #define NSAPI_MAC_SIZE 18 |
| nexpaq | 0:6c56fb4bc5f0 | 60 | |
| nexpaq | 0:6c56fb4bc5f0 | 61 | /** Maximum number of bytes for MAC address |
| nexpaq | 0:6c56fb4bc5f0 | 62 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 63 | #define NSAPI_MAC_BYTES 6 |
| nexpaq | 0:6c56fb4bc5f0 | 64 | |
| nexpaq | 0:6c56fb4bc5f0 | 65 | /** Size of IPv4 representation |
| nexpaq | 0:6c56fb4bc5f0 | 66 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 67 | #define NSAPI_IPv4_SIZE 16 |
| nexpaq | 0:6c56fb4bc5f0 | 68 | |
| nexpaq | 0:6c56fb4bc5f0 | 69 | /** Number of bytes in IPv4 address |
| nexpaq | 0:6c56fb4bc5f0 | 70 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 71 | #define NSAPI_IPv4_BYTES 4 |
| nexpaq | 0:6c56fb4bc5f0 | 72 | |
| nexpaq | 0:6c56fb4bc5f0 | 73 | /** Size of IPv6 representation |
| nexpaq | 0:6c56fb4bc5f0 | 74 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 75 | #define NSAPI_IPv6_SIZE 40 |
| nexpaq | 0:6c56fb4bc5f0 | 76 | |
| nexpaq | 0:6c56fb4bc5f0 | 77 | /** Number of bytes in IPv6 address |
| nexpaq | 0:6c56fb4bc5f0 | 78 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 79 | #define NSAPI_IPv6_BYTES 16 |
| nexpaq | 0:6c56fb4bc5f0 | 80 | |
| nexpaq | 0:6c56fb4bc5f0 | 81 | /** Enum of IP address versions |
| nexpaq | 0:6c56fb4bc5f0 | 82 | * |
| nexpaq | 0:6c56fb4bc5f0 | 83 | * The IP version specifies the type of an IP address. |
| nexpaq | 0:6c56fb4bc5f0 | 84 | * |
| nexpaq | 0:6c56fb4bc5f0 | 85 | * @enum nsapi_version_t |
| nexpaq | 0:6c56fb4bc5f0 | 86 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 87 | typedef enum nsapi_version { |
| nexpaq | 0:6c56fb4bc5f0 | 88 | NSAPI_IPv4, /*!< Address is IPv4 */ |
| nexpaq | 0:6c56fb4bc5f0 | 89 | NSAPI_IPv6, /*!< Address is IPv6 */ |
| nexpaq | 0:6c56fb4bc5f0 | 90 | } nsapi_version_t; |
| nexpaq | 0:6c56fb4bc5f0 | 91 | |
| nexpaq | 0:6c56fb4bc5f0 | 92 | /** IP address structure for passing IP addresses by value |
| nexpaq | 0:6c56fb4bc5f0 | 93 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 94 | typedef struct nsapi_addr { |
| nexpaq | 0:6c56fb4bc5f0 | 95 | /** IP version |
| nexpaq | 0:6c56fb4bc5f0 | 96 | * NSAPI_IPv4 or NSAPI_IPv6 |
| nexpaq | 0:6c56fb4bc5f0 | 97 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 98 | nsapi_version_t version; |
| nexpaq | 0:6c56fb4bc5f0 | 99 | |
| nexpaq | 0:6c56fb4bc5f0 | 100 | /** IP address |
| nexpaq | 0:6c56fb4bc5f0 | 101 | * The raw bytes of the IP address stored in big-endian format |
| nexpaq | 0:6c56fb4bc5f0 | 102 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 103 | uint8_t bytes[NSAPI_IP_BYTES]; |
| nexpaq | 0:6c56fb4bc5f0 | 104 | } nsapi_addr_t; |
| nexpaq | 0:6c56fb4bc5f0 | 105 | |
| nexpaq | 0:6c56fb4bc5f0 | 106 | |
| nexpaq | 0:6c56fb4bc5f0 | 107 | /** Opaque handle for network sockets |
| nexpaq | 0:6c56fb4bc5f0 | 108 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 109 | typedef void *nsapi_socket_t; |
| nexpaq | 0:6c56fb4bc5f0 | 110 | |
| nexpaq | 0:6c56fb4bc5f0 | 111 | |
| nexpaq | 0:6c56fb4bc5f0 | 112 | /** Enum of socket protocols |
| nexpaq | 0:6c56fb4bc5f0 | 113 | * |
| nexpaq | 0:6c56fb4bc5f0 | 114 | * The socket protocol specifies a particular protocol to |
| nexpaq | 0:6c56fb4bc5f0 | 115 | * be used with a newly created socket. |
| nexpaq | 0:6c56fb4bc5f0 | 116 | * |
| nexpaq | 0:6c56fb4bc5f0 | 117 | * @enum nsapi_protocol_t |
| nexpaq | 0:6c56fb4bc5f0 | 118 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 119 | typedef enum nsapi_protocol { |
| nexpaq | 0:6c56fb4bc5f0 | 120 | NSAPI_TCP, /*!< Socket is of TCP type */ |
| nexpaq | 0:6c56fb4bc5f0 | 121 | NSAPI_UDP, /*!< Socket is of UDP type */ |
| nexpaq | 0:6c56fb4bc5f0 | 122 | } nsapi_protocol_t; |
| nexpaq | 0:6c56fb4bc5f0 | 123 | |
| nexpaq | 0:6c56fb4bc5f0 | 124 | /* Enum of standardized stack option levels |
| nexpaq | 0:6c56fb4bc5f0 | 125 | * |
| nexpaq | 0:6c56fb4bc5f0 | 126 | * @enum nsapi_level_t |
| nexpaq | 0:6c56fb4bc5f0 | 127 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 128 | typedef enum nsapi_level { |
| nexpaq | 0:6c56fb4bc5f0 | 129 | NSAPI_STACK, /*!< Stack option level */ |
| nexpaq | 0:6c56fb4bc5f0 | 130 | NSAPI_SOCKET, /*!< Socket option level */ |
| nexpaq | 0:6c56fb4bc5f0 | 131 | } nsapi_level_t; |
| nexpaq | 0:6c56fb4bc5f0 | 132 | |
| nexpaq | 0:6c56fb4bc5f0 | 133 | /* Enum of standardized stack options |
| nexpaq | 0:6c56fb4bc5f0 | 134 | * |
| nexpaq | 0:6c56fb4bc5f0 | 135 | * These options may not be supported on all stacks, in which |
| nexpaq | 0:6c56fb4bc5f0 | 136 | * case NSAPI_ERROR_UNSUPPORTED may be returned from setsockopt. |
| nexpaq | 0:6c56fb4bc5f0 | 137 | * |
| nexpaq | 0:6c56fb4bc5f0 | 138 | * @enum nsapi_option_t |
| nexpaq | 0:6c56fb4bc5f0 | 139 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 140 | typedef enum nsapi_option { |
| nexpaq | 0:6c56fb4bc5f0 | 141 | NSAPI_REUSEADDR, /*!< Allow bind to reuse local addresses */ |
| nexpaq | 0:6c56fb4bc5f0 | 142 | NSAPI_KEEPALIVE, /*!< Enables sending of keepalive messages */ |
| nexpaq | 0:6c56fb4bc5f0 | 143 | NSAPI_KEEPIDLE, /*!< Sets timeout value to initiate keepalive */ |
| nexpaq | 0:6c56fb4bc5f0 | 144 | NSAPI_KEEPINTVL, /*!< Sets timeout value for keepalive */ |
| nexpaq | 0:6c56fb4bc5f0 | 145 | NSAPI_LINGER, /*!< Keeps close from returning until queues empty */ |
| nexpaq | 0:6c56fb4bc5f0 | 146 | NSAPI_SNDBUF, /*!< Sets send buffer size */ |
| nexpaq | 0:6c56fb4bc5f0 | 147 | NSAPI_RCVBUF, /*!< Sets recv buffer size */ |
| nexpaq | 0:6c56fb4bc5f0 | 148 | } nsapi_option_t; |
| nexpaq | 0:6c56fb4bc5f0 | 149 | |
| nexpaq | 0:6c56fb4bc5f0 | 150 | |
| nexpaq | 0:6c56fb4bc5f0 | 151 | /** nsapi_stack structure |
| nexpaq | 0:6c56fb4bc5f0 | 152 | * |
| nexpaq | 0:6c56fb4bc5f0 | 153 | * Stack structure representing a specific instance of a stack. |
| nexpaq | 0:6c56fb4bc5f0 | 154 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 155 | typedef struct nsapi_stack { |
| nexpaq | 0:6c56fb4bc5f0 | 156 | /** Network stack operation table |
| nexpaq | 0:6c56fb4bc5f0 | 157 | * |
| nexpaq | 0:6c56fb4bc5f0 | 158 | * Provides access to the underlying api of the stack. This is not |
| nexpaq | 0:6c56fb4bc5f0 | 159 | * flattened into the nsapi_stack to allow allocation in read-only |
| nexpaq | 0:6c56fb4bc5f0 | 160 | * memory. |
| nexpaq | 0:6c56fb4bc5f0 | 161 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 162 | const struct nsapi_stack_api *stack_api; |
| nexpaq | 0:6c56fb4bc5f0 | 163 | |
| nexpaq | 0:6c56fb4bc5f0 | 164 | /** Opaque handle for network stacks |
| nexpaq | 0:6c56fb4bc5f0 | 165 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 166 | void *stack; |
| nexpaq | 0:6c56fb4bc5f0 | 167 | |
| nexpaq | 0:6c56fb4bc5f0 | 168 | // Internal nsapi buffer |
| nexpaq | 0:6c56fb4bc5f0 | 169 | unsigned _stack_buffer[16]; |
| nexpaq | 0:6c56fb4bc5f0 | 170 | } nsapi_stack_t; |
| nexpaq | 0:6c56fb4bc5f0 | 171 | |
| nexpaq | 0:6c56fb4bc5f0 | 172 | /** nsapi_stack_api structure |
| nexpaq | 0:6c56fb4bc5f0 | 173 | * |
| nexpaq | 0:6c56fb4bc5f0 | 174 | * Common api structure for network stack operations. A network stack |
| nexpaq | 0:6c56fb4bc5f0 | 175 | * can provide a nsapi_stack_api structure filled out with the |
| nexpaq | 0:6c56fb4bc5f0 | 176 | * appropriate implementation. |
| nexpaq | 0:6c56fb4bc5f0 | 177 | * |
| nexpaq | 0:6c56fb4bc5f0 | 178 | * Unsupported operations can be left as null pointers. |
| nexpaq | 0:6c56fb4bc5f0 | 179 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 180 | typedef struct nsapi_stack_api |
| nexpaq | 0:6c56fb4bc5f0 | 181 | { |
| nexpaq | 0:6c56fb4bc5f0 | 182 | /** Get the local IP address |
| nexpaq | 0:6c56fb4bc5f0 | 183 | * |
| nexpaq | 0:6c56fb4bc5f0 | 184 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 185 | * @return Local IP Address or null address if not connected |
| nexpaq | 0:6c56fb4bc5f0 | 186 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 187 | nsapi_addr_t (*get_ip_address)(nsapi_stack_t *stack); |
| nexpaq | 0:6c56fb4bc5f0 | 188 | |
| nexpaq | 0:6c56fb4bc5f0 | 189 | /** Translates a hostname to an IP address |
| nexpaq | 0:6c56fb4bc5f0 | 190 | * |
| nexpaq | 0:6c56fb4bc5f0 | 191 | * The hostname may be either a domain name or an IP address. If the |
| nexpaq | 0:6c56fb4bc5f0 | 192 | * hostname is an IP address, no network transactions will be performed. |
| nexpaq | 0:6c56fb4bc5f0 | 193 | * |
| nexpaq | 0:6c56fb4bc5f0 | 194 | * If no stack-specific DNS resolution is provided, the hostname |
| nexpaq | 0:6c56fb4bc5f0 | 195 | * will be resolve using a UDP socket on the stack. |
| nexpaq | 0:6c56fb4bc5f0 | 196 | * |
| nexpaq | 0:6c56fb4bc5f0 | 197 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 198 | * @param addr Destination for the host IP address |
| nexpaq | 0:6c56fb4bc5f0 | 199 | * @param host Hostname to resolve |
| nexpaq | 0:6c56fb4bc5f0 | 200 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 201 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 202 | int (*gethostbyname)(nsapi_stack_t *stack, nsapi_addr_t *addr, const char *host); |
| nexpaq | 0:6c56fb4bc5f0 | 203 | |
| nexpaq | 0:6c56fb4bc5f0 | 204 | /* Set stack-specific stack options |
| nexpaq | 0:6c56fb4bc5f0 | 205 | * |
| nexpaq | 0:6c56fb4bc5f0 | 206 | * The setstackopt allow an application to pass stack-specific hints |
| nexpaq | 0:6c56fb4bc5f0 | 207 | * to the underlying stack. For unsupported options, |
| nexpaq | 0:6c56fb4bc5f0 | 208 | * NSAPI_ERROR_UNSUPPORTED is returned and the stack is unmodified. |
| nexpaq | 0:6c56fb4bc5f0 | 209 | * |
| nexpaq | 0:6c56fb4bc5f0 | 210 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 211 | * @param level Stack-specific protocol level |
| nexpaq | 0:6c56fb4bc5f0 | 212 | * @param optname Stack-specific option identifier |
| nexpaq | 0:6c56fb4bc5f0 | 213 | * @param optval Option value |
| nexpaq | 0:6c56fb4bc5f0 | 214 | * @param optlen Length of the option value |
| nexpaq | 0:6c56fb4bc5f0 | 215 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 216 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 217 | int (*setstackopt)(nsapi_stack_t *stack, int level, int optname, const void *optval, unsigned optlen); |
| nexpaq | 0:6c56fb4bc5f0 | 218 | |
| nexpaq | 0:6c56fb4bc5f0 | 219 | /* Get stack-specific stack options |
| nexpaq | 0:6c56fb4bc5f0 | 220 | * |
| nexpaq | 0:6c56fb4bc5f0 | 221 | * The getstackopt allow an application to retrieve stack-specific hints |
| nexpaq | 0:6c56fb4bc5f0 | 222 | * from the underlying stack. For unsupported options, |
| nexpaq | 0:6c56fb4bc5f0 | 223 | * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified. |
| nexpaq | 0:6c56fb4bc5f0 | 224 | * |
| nexpaq | 0:6c56fb4bc5f0 | 225 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 226 | * @param level Stack-specific protocol level |
| nexpaq | 0:6c56fb4bc5f0 | 227 | * @param optname Stack-specific option identifier |
| nexpaq | 0:6c56fb4bc5f0 | 228 | * @param optval Destination for option value |
| nexpaq | 0:6c56fb4bc5f0 | 229 | * @param optlen Length of the option value |
| nexpaq | 0:6c56fb4bc5f0 | 230 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 231 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 232 | int (*getstackopt)(nsapi_stack_t *stack, int level, int optname, void *optval, unsigned *optlen); |
| nexpaq | 0:6c56fb4bc5f0 | 233 | |
| nexpaq | 0:6c56fb4bc5f0 | 234 | /** Opens a socket |
| nexpaq | 0:6c56fb4bc5f0 | 235 | * |
| nexpaq | 0:6c56fb4bc5f0 | 236 | * Creates a network socket and stores it in the specified handle. |
| nexpaq | 0:6c56fb4bc5f0 | 237 | * The handle must be passed to following calls on the socket. |
| nexpaq | 0:6c56fb4bc5f0 | 238 | * |
| nexpaq | 0:6c56fb4bc5f0 | 239 | * A stack may have a finite number of sockets, in this case |
| nexpaq | 0:6c56fb4bc5f0 | 240 | * NSAPI_ERROR_NO_SOCKET is returned if no socket is available. |
| nexpaq | 0:6c56fb4bc5f0 | 241 | * |
| nexpaq | 0:6c56fb4bc5f0 | 242 | * @param stack Stack context |
| nexpaq | 0:6c56fb4bc5f0 | 243 | * @param socket Destination for the handle to a newly created socket |
| nexpaq | 0:6c56fb4bc5f0 | 244 | * @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP |
| nexpaq | 0:6c56fb4bc5f0 | 245 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 246 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 247 | int (*socket_open)(nsapi_stack_t *stack, nsapi_socket_t *socket, nsapi_protocol_t proto); |
| nexpaq | 0:6c56fb4bc5f0 | 248 | |
| nexpaq | 0:6c56fb4bc5f0 | 249 | /** Close the socket |
| nexpaq | 0:6c56fb4bc5f0 | 250 | * |
| nexpaq | 0:6c56fb4bc5f0 | 251 | * Closes any open connection and deallocates any memory associated |
| nexpaq | 0:6c56fb4bc5f0 | 252 | * with the socket. |
| nexpaq | 0:6c56fb4bc5f0 | 253 | * |
| nexpaq | 0:6c56fb4bc5f0 | 254 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 255 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 256 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 257 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 258 | int (*socket_close)(nsapi_stack_t *stack, nsapi_socket_t socket); |
| nexpaq | 0:6c56fb4bc5f0 | 259 | |
| nexpaq | 0:6c56fb4bc5f0 | 260 | /** Bind a specific address to a socket |
| nexpaq | 0:6c56fb4bc5f0 | 261 | * |
| nexpaq | 0:6c56fb4bc5f0 | 262 | * Binding a socket specifies the address and port on which to recieve |
| nexpaq | 0:6c56fb4bc5f0 | 263 | * data. If the IP address is zeroed, only the port is bound. |
| nexpaq | 0:6c56fb4bc5f0 | 264 | * |
| nexpaq | 0:6c56fb4bc5f0 | 265 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 266 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 267 | * @param addr Local address to bind, may be null |
| nexpaq | 0:6c56fb4bc5f0 | 268 | * @param port Local port to bind |
| nexpaq | 0:6c56fb4bc5f0 | 269 | * @return 0 on success, negative error code on failure. |
| nexpaq | 0:6c56fb4bc5f0 | 270 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 271 | int (*socket_bind)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port); |
| nexpaq | 0:6c56fb4bc5f0 | 272 | |
| nexpaq | 0:6c56fb4bc5f0 | 273 | /** Listen for connections on a TCP socket |
| nexpaq | 0:6c56fb4bc5f0 | 274 | * |
| nexpaq | 0:6c56fb4bc5f0 | 275 | * Marks the socket as a passive socket that can be used to accept |
| nexpaq | 0:6c56fb4bc5f0 | 276 | * incoming connections. |
| nexpaq | 0:6c56fb4bc5f0 | 277 | * |
| nexpaq | 0:6c56fb4bc5f0 | 278 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 279 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 280 | * @param backlog Number of pending connections that can be queued |
| nexpaq | 0:6c56fb4bc5f0 | 281 | * simultaneously |
| nexpaq | 0:6c56fb4bc5f0 | 282 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 283 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 284 | int (*socket_listen)(nsapi_stack_t *stack, nsapi_socket_t socket, int backlog); |
| nexpaq | 0:6c56fb4bc5f0 | 285 | |
| nexpaq | 0:6c56fb4bc5f0 | 286 | /** Connects TCP socket to a remote host |
| nexpaq | 0:6c56fb4bc5f0 | 287 | * |
| nexpaq | 0:6c56fb4bc5f0 | 288 | * Initiates a connection to a remote server specified by the |
| nexpaq | 0:6c56fb4bc5f0 | 289 | * indicated address. |
| nexpaq | 0:6c56fb4bc5f0 | 290 | * |
| nexpaq | 0:6c56fb4bc5f0 | 291 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 292 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 293 | * @param addr The address of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 294 | * @param port The port of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 295 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 296 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 297 | int (*socket_connect)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port); |
| nexpaq | 0:6c56fb4bc5f0 | 298 | |
| nexpaq | 0:6c56fb4bc5f0 | 299 | /** Accepts a connection on a TCP socket |
| nexpaq | 0:6c56fb4bc5f0 | 300 | * |
| nexpaq | 0:6c56fb4bc5f0 | 301 | * The server socket must be bound and set to listen for connections. |
| nexpaq | 0:6c56fb4bc5f0 | 302 | * On a new connection, creates a network socket and stores it in the |
| nexpaq | 0:6c56fb4bc5f0 | 303 | * specified handle. The handle must be passed to following calls on |
| nexpaq | 0:6c56fb4bc5f0 | 304 | * the socket. |
| nexpaq | 0:6c56fb4bc5f0 | 305 | * |
| nexpaq | 0:6c56fb4bc5f0 | 306 | * A stack may have a finite number of sockets, in this case |
| nexpaq | 0:6c56fb4bc5f0 | 307 | * NSAPI_ERROR_NO_SOCKET is returned if no socket is available. |
| nexpaq | 0:6c56fb4bc5f0 | 308 | * |
| nexpaq | 0:6c56fb4bc5f0 | 309 | * This call is non-blocking. If accept would block, |
| nexpaq | 0:6c56fb4bc5f0 | 310 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| nexpaq | 0:6c56fb4bc5f0 | 311 | * |
| nexpaq | 0:6c56fb4bc5f0 | 312 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 313 | * @param server Socket handle to server to accept from |
| nexpaq | 0:6c56fb4bc5f0 | 314 | * @param socket Destination for a handle to the newly created socket |
| nexpaq | 0:6c56fb4bc5f0 | 315 | * @param addr Destination for the address of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 316 | * @param port Destination for the port of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 317 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 318 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 319 | int (*socket_accept)(nsapi_stack_t *stack, nsapi_socket_t server, nsapi_socket_t *socket, nsapi_addr_t *addr, uint16_t *port); |
| nexpaq | 0:6c56fb4bc5f0 | 320 | |
| nexpaq | 0:6c56fb4bc5f0 | 321 | /** Send data over a TCP socket |
| nexpaq | 0:6c56fb4bc5f0 | 322 | * |
| nexpaq | 0:6c56fb4bc5f0 | 323 | * The socket must be connected to a remote host. Returns the number of |
| nexpaq | 0:6c56fb4bc5f0 | 324 | * bytes sent from the buffer. |
| nexpaq | 0:6c56fb4bc5f0 | 325 | * |
| nexpaq | 0:6c56fb4bc5f0 | 326 | * This call is non-blocking. If send would block, |
| nexpaq | 0:6c56fb4bc5f0 | 327 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| nexpaq | 0:6c56fb4bc5f0 | 328 | * |
| nexpaq | 0:6c56fb4bc5f0 | 329 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 330 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 331 | * @param data Buffer of data to send to the host |
| nexpaq | 0:6c56fb4bc5f0 | 332 | * @param size Size of the buffer in bytes |
| nexpaq | 0:6c56fb4bc5f0 | 333 | * @return Number of sent bytes on success, negative error |
| nexpaq | 0:6c56fb4bc5f0 | 334 | * code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 335 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 336 | int (*socket_send)(nsapi_stack_t *stack, nsapi_socket_t socket, const void *data, unsigned size); |
| nexpaq | 0:6c56fb4bc5f0 | 337 | |
| nexpaq | 0:6c56fb4bc5f0 | 338 | /** Receive data over a TCP socket |
| nexpaq | 0:6c56fb4bc5f0 | 339 | * |
| nexpaq | 0:6c56fb4bc5f0 | 340 | * The socket must be connected to a remote host. Returns the number of |
| nexpaq | 0:6c56fb4bc5f0 | 341 | * bytes received into the buffer. |
| nexpaq | 0:6c56fb4bc5f0 | 342 | * |
| nexpaq | 0:6c56fb4bc5f0 | 343 | * This call is non-blocking. If recv would block, |
| nexpaq | 0:6c56fb4bc5f0 | 344 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| nexpaq | 0:6c56fb4bc5f0 | 345 | * |
| nexpaq | 0:6c56fb4bc5f0 | 346 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 347 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 348 | * @param data Destination buffer for data received from the host |
| nexpaq | 0:6c56fb4bc5f0 | 349 | * @param size Size of the buffer in bytes |
| nexpaq | 0:6c56fb4bc5f0 | 350 | * @return Number of received bytes on success, negative error |
| nexpaq | 0:6c56fb4bc5f0 | 351 | * code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 352 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 353 | int (*socket_recv)(nsapi_stack_t *stack, nsapi_socket_t socket, void *data, unsigned size); |
| nexpaq | 0:6c56fb4bc5f0 | 354 | |
| nexpaq | 0:6c56fb4bc5f0 | 355 | /** Send a packet over a UDP socket |
| nexpaq | 0:6c56fb4bc5f0 | 356 | * |
| nexpaq | 0:6c56fb4bc5f0 | 357 | * Sends data to the specified address. Returns the number of bytes |
| nexpaq | 0:6c56fb4bc5f0 | 358 | * sent from the buffer. |
| nexpaq | 0:6c56fb4bc5f0 | 359 | * |
| nexpaq | 0:6c56fb4bc5f0 | 360 | * This call is non-blocking. If sendto would block, |
| nexpaq | 0:6c56fb4bc5f0 | 361 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| nexpaq | 0:6c56fb4bc5f0 | 362 | * |
| nexpaq | 0:6c56fb4bc5f0 | 363 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 364 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 365 | * @param addr The address of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 366 | * @param port The port of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 367 | * @param data Buffer of data to send to the host |
| nexpaq | 0:6c56fb4bc5f0 | 368 | * @param size Size of the buffer in bytes |
| nexpaq | 0:6c56fb4bc5f0 | 369 | * @return Number of sent bytes on success, negative error |
| nexpaq | 0:6c56fb4bc5f0 | 370 | * code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 371 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 372 | int (*socket_sendto)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t addr, uint16_t port, const void *data, unsigned size); |
| nexpaq | 0:6c56fb4bc5f0 | 373 | |
| nexpaq | 0:6c56fb4bc5f0 | 374 | /** Receive a packet over a UDP socket |
| nexpaq | 0:6c56fb4bc5f0 | 375 | * |
| nexpaq | 0:6c56fb4bc5f0 | 376 | * Receives data and stores the source address in address if address |
| nexpaq | 0:6c56fb4bc5f0 | 377 | * is not NULL. Returns the number of bytes received into the buffer. |
| nexpaq | 0:6c56fb4bc5f0 | 378 | * |
| nexpaq | 0:6c56fb4bc5f0 | 379 | * This call is non-blocking. If recvfrom would block, |
| nexpaq | 0:6c56fb4bc5f0 | 380 | * NSAPI_ERROR_WOULD_BLOCK is returned immediately. |
| nexpaq | 0:6c56fb4bc5f0 | 381 | * |
| nexpaq | 0:6c56fb4bc5f0 | 382 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 383 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 384 | * @param addr Destination for the address of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 385 | * @param port Destination for the port of the remote host |
| nexpaq | 0:6c56fb4bc5f0 | 386 | * @param data Destination buffer for data received from the host |
| nexpaq | 0:6c56fb4bc5f0 | 387 | * @param size Size of the buffer in bytes |
| nexpaq | 0:6c56fb4bc5f0 | 388 | * @return Number of received bytes on success, negative error |
| nexpaq | 0:6c56fb4bc5f0 | 389 | * code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 390 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 391 | int (*socket_recvfrom)(nsapi_stack_t *stack, nsapi_socket_t socket, nsapi_addr_t *addr, uint16_t *port, void *buffer, unsigned size); |
| nexpaq | 0:6c56fb4bc5f0 | 392 | |
| nexpaq | 0:6c56fb4bc5f0 | 393 | /** Register a callback on state change of the socket |
| nexpaq | 0:6c56fb4bc5f0 | 394 | * |
| nexpaq | 0:6c56fb4bc5f0 | 395 | * The specified callback will be called on state changes such as when |
| nexpaq | 0:6c56fb4bc5f0 | 396 | * the socket can recv/send/accept successfully and on when an error |
| nexpaq | 0:6c56fb4bc5f0 | 397 | * occurs. The callback may also be called spuriously without reason. |
| nexpaq | 0:6c56fb4bc5f0 | 398 | * |
| nexpaq | 0:6c56fb4bc5f0 | 399 | * The callback may be called in an interrupt context and should not |
| nexpaq | 0:6c56fb4bc5f0 | 400 | * perform expensive operations such as recv/send calls. |
| nexpaq | 0:6c56fb4bc5f0 | 401 | * |
| nexpaq | 0:6c56fb4bc5f0 | 402 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 403 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 404 | * @param callback Function to call on state change |
| nexpaq | 0:6c56fb4bc5f0 | 405 | * @param data Argument to pass to callback |
| nexpaq | 0:6c56fb4bc5f0 | 406 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 407 | void (*socket_attach)(nsapi_stack_t *stack, nsapi_socket_t socket, void (*callback)(void *), void *data); |
| nexpaq | 0:6c56fb4bc5f0 | 408 | |
| nexpaq | 0:6c56fb4bc5f0 | 409 | /* Set stack-specific socket options |
| nexpaq | 0:6c56fb4bc5f0 | 410 | * |
| nexpaq | 0:6c56fb4bc5f0 | 411 | * The setsockopt allow an application to pass stack-specific hints |
| nexpaq | 0:6c56fb4bc5f0 | 412 | * to the underlying stack. For unsupported options, |
| nexpaq | 0:6c56fb4bc5f0 | 413 | * NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified. |
| nexpaq | 0:6c56fb4bc5f0 | 414 | * |
| nexpaq | 0:6c56fb4bc5f0 | 415 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 416 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 417 | * @param level Stack-specific protocol level |
| nexpaq | 0:6c56fb4bc5f0 | 418 | * @param optname Stack-specific option identifier |
| nexpaq | 0:6c56fb4bc5f0 | 419 | * @param optval Option value |
| nexpaq | 0:6c56fb4bc5f0 | 420 | * @param optlen Length of the option value |
| nexpaq | 0:6c56fb4bc5f0 | 421 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 422 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 423 | int (*setsockopt)(nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, const void *optval, unsigned optlen); |
| nexpaq | 0:6c56fb4bc5f0 | 424 | |
| nexpaq | 0:6c56fb4bc5f0 | 425 | /* Get stack-specific socket options |
| nexpaq | 0:6c56fb4bc5f0 | 426 | * |
| nexpaq | 0:6c56fb4bc5f0 | 427 | * The getstackopt allow an application to retrieve stack-specific hints |
| nexpaq | 0:6c56fb4bc5f0 | 428 | * from the underlying stack. For unsupported options, |
| nexpaq | 0:6c56fb4bc5f0 | 429 | * NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified. |
| nexpaq | 0:6c56fb4bc5f0 | 430 | * |
| nexpaq | 0:6c56fb4bc5f0 | 431 | * @param stack Stack handle |
| nexpaq | 0:6c56fb4bc5f0 | 432 | * @param socket Socket handle |
| nexpaq | 0:6c56fb4bc5f0 | 433 | * @param level Stack-specific protocol level |
| nexpaq | 0:6c56fb4bc5f0 | 434 | * @param optname Stack-specific option identifier |
| nexpaq | 0:6c56fb4bc5f0 | 435 | * @param optval Destination for option value |
| nexpaq | 0:6c56fb4bc5f0 | 436 | * @param optlen Length of the option value |
| nexpaq | 0:6c56fb4bc5f0 | 437 | * @return 0 on success, negative error code on failure |
| nexpaq | 0:6c56fb4bc5f0 | 438 | */ |
| nexpaq | 0:6c56fb4bc5f0 | 439 | int (*getsockopt)(nsapi_stack_t *stack, nsapi_socket_t socket, int level, int optname, void *optval, unsigned *optlen); |
| nexpaq | 0:6c56fb4bc5f0 | 440 | } nsapi_stack_api_t; |
| nexpaq | 0:6c56fb4bc5f0 | 441 | |
| nexpaq | 0:6c56fb4bc5f0 | 442 | |
| nexpaq | 0:6c56fb4bc5f0 | 443 | #ifdef __cplusplus |
| nexpaq | 0:6c56fb4bc5f0 | 444 | } |
| nexpaq | 0:6c56fb4bc5f0 | 445 | #endif |
| nexpaq | 0:6c56fb4bc5f0 | 446 | |
| nexpaq | 0:6c56fb4bc5f0 | 447 | #endif |