API Reference Manual
r8305
|
00001 /* 00002 * Copyright (C) 2012, H&D Wireless AB All rights reserved. 00003 * 00004 * The license to use this software in whole and in part and to 00005 * redistribute it in any form follows with the WiFi HW module from H&D 00006 * Wireless and is granted under the following restrictions: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * 3. The name of H&D Wireless AB may not be used to endorse or promote 00016 * products derived from this software without specific prior written 00017 * permission. 00018 * 00019 * 4. The software may only be used together with hardware from H&D 00020 * Wireless all other use is prohibited. 00021 * 00022 * 5. The license to use and redistribute the software is granted 00023 * together with the purchase of a hardware platform on a one to one 00024 * basis. 00025 * 00026 * 6. The binary code may not be reversed engineered or by other means 00027 * copied to circumvent this license. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY H&D WIRELESS AB ``AS IS'' AND ANY 00030 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00031 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00032 * PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT 00033 * SHALL HD WIRELESS AB BE LIABLE FOR ANY DIRECT, INDIRECT, 00034 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00035 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00036 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00037 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00038 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00039 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00040 * OF THE POSSIBILITY OF SUCH DAMAGE. 00041 * 00042 * For more information regarding this software license Contact H&D 00043 * Wireless AB (support@hd-wireless.se). 00044 * 00045 */ 00046 00047 00130 #ifndef WLP_API_H 00131 #define WLP_API_H 00132 00133 #include <owl_cc.h> 00134 00135 #if !defined(WLP_STACK_OFFLOAD) 00136 # define WLP_STACK_OFFLOAD 1 00137 #endif 00138 00139 #if !defined(WLP_STACK_LWIP) 00140 # define WLP_STACK_LWIP 0 00141 #endif 00142 00143 /* Define if application wants a trampoilne, e.g. if a thread layer is used */ 00144 #if !defined(WLP_TRAMPOLINE) 00145 # define WLP_TRAMPOLINE 0 00146 #endif 00147 00148 /* API version */ 00149 #define WLP_VERSION(a,b,c) (((uint32_t)((a) & 0xff) << 16) | \ 00150 ((uint32_t)((b) & 0xff) << 8) | \ 00151 (uint32_t)((c) & 0xff)) 00152 #define WLP_MAJOR_VERSION(code) ((uint16_t)((code) >> 16) & 0xff) 00153 #define WLP_MINOR_VERSION(code) ((uint16_t)((code) >> 8) & 0xff) 00154 #define WLP_PATCH_VERSION(code) ((uint16_t)((code)) & 0xff) 00155 #define WLP_VERSION_CODE WLP_VERSION(2,0,0) 00156 00157 #define WLP_FAILURE -1 00158 #define WLP_ERR_PARAM -2 00159 #define WLP_ERR_MEM -3 00160 #define WLP_ERR_CONN -4 00161 #define WLP_ERR_STATE -5 00162 #define WLP_ERR_PARSE -6 00163 #define WLP_ERR_PATH -7 00164 #define WLP_ERR_TYPE -8 00165 #define WLP_ERR_PERM -9 00166 #define WLP_ERR_NOTSUPP -10 00167 #define WLP_ERR_RANGE -11 00168 #define WLP_ERR_SIZE -12 00169 #define WLP_ERR_AGAIN -13 00170 #define WLP_ERR_BUSY -14 00171 #define WLP_ERR_DISABLED -15 00172 #define WLP_ERR_PROTO -16 00173 #define WLP_ERR_TIMEOUT -17 00174 #define WLP_ERR_IGNORED -18 00175 #define WLP_ERR_CANCEL -19 00176 #define WLP_ERR_SYNC -20 00177 #define WLP_ERR_ABORT -21 00178 #define WLP_ERR_INUSE -22 00179 #define WLP_ERR_USAGE -23 00180 #define WLP_ERR_CHECKSUM -24 00183 #define WLP_INVALID_SOCKET_ID 0 00184 00186 #define WLP_INTERFACE_UART 0 00187 #define WLP_INTERFACE_SPI 1 00188 00189 /* !\ingroup wlp_api */ 00190 #define WLP_CAP_HA_PIN (1 << 0) 00191 #define WLP_CAP_WAKEUP_PIN (1 << 1) 00196 enum wlp_auth_mode { 00197 WLP_AUTH_AUTO = 0, 00198 WLP_AUTH_WEP, 00199 WLP_AUTH_WPA_PSK, 00200 WLP_AUTH_WPA2_PSK, 00201 WLP_AUTH_WPA, 00202 WLP_AUTH_WPA2, 00203 }; 00204 00205 #define WLP_SOCK_STREAM 0 00206 #define WLP_SOCK_DGRAM 1 00207 #define WLP_SOCK_RAW 2 00208 00209 enum wlp_fw_upgrade_method { 00210 WLP_UPGRADE_METHOD_HTTP_POST 00211 }; 00212 00213 #define WLP_MAX_PASS_LEN 64 00214 #define WLP_SNR_UNKNOWN -128 00215 #define WLP_RSSI_UNKNOWN -128 00216 #define WLP_SSID_MAX_LENGTH 32 00217 #define WLP_MAC_ADDR_LENGTH 6 00218 00219 #include <owl_beginpack.h> 00220 00229 struct wlp_ssid { 00230 char ssid[WLP_SSID_MAX_LENGTH]; 00231 uint8_t len; 00232 } OWL_PACKED; 00233 00234 00241 struct wlp_mac_addr { 00242 uint8_t octet[WLP_MAC_ADDR_LENGTH]; 00243 } OWL_PACKED; 00244 00245 #include <owl_endpack.h> 00246 00247 00248 #define WLP_MODE_STA 0 00249 #define WLP_MODE_AP 1 00250 #define WLP_MODE_ADHOC 2 00251 00252 enum wlp_conn_type { 00253 WLP_CONN_TYPE_INFRA, 00254 WLP_CONN_TYPE_ADHOC 00255 }; 00256 00257 00258 #if !WLP_STACK_LWIP 00259 00260 /* 00261 * The struct ip_addr type is based on work from the lwIP network stack. 00262 * 00263 */ 00264 00265 /* 00266 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00267 * All rights reserved. 00268 * 00269 * Redistribution and use in source and binary forms, with or without 00270 * modification, are permitted provided that the following conditions are met: 00271 * 00272 * 1. Redistributions of source code must retain the above copyright notice, 00273 * this list of conditions and the following disclaimer. 00274 * 2. Redistributions in binary form must reproduce the above copyright notice, 00275 * this list of conditions and the following disclaimer in the documentation 00276 * and/or other materials provided with the distribution. 00277 * 3. The name of the author may not be used to endorse or promote products 00278 * derived from this software without specific prior written permission. 00279 * 00280 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00281 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00282 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 00283 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00284 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00285 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00286 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00287 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00288 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00289 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00290 */ 00291 00292 struct ip_addr { 00293 uint32_t addr; 00294 }; 00295 00296 extern const struct ip_addr ip_addr_any; 00297 00298 #define IP_ADDR_ANY ((struct ip_addr *) &ip_addr_any) 00299 #define IP4_ADDR(ipaddr, a,b,c,d) \ 00300 (ipaddr)->addr = htonl(((uint32_t)((a) & 0xff) << 24) | \ 00301 ((uint32_t)((b) & 0xff) << 16) | \ 00302 ((uint32_t)((c) & 0xff) << 8) | \ 00303 (uint32_t)((d) & 0xff)) 00304 #define ip_addr_set(dest, src) \ 00305 (dest)->addr = ((src) == NULL? 0: (src)->addr) 00306 #define ip_addr_netcmp(addr1, addr2, mask) \ 00307 (((addr1)->addr & (mask)->addr) == ((addr2)->addr & (mask)->addr)) 00308 #define ip_addr_cmp(addr1, addr2) \ 00309 ((addr1)->addr == (addr2)->addr) 00310 #define ip_addr_isany(addr1) \ 00311 ((addr1) == NULL || (addr1)->addr == 0) 00312 00313 #define ip4_addr1(ipaddr) ((uint16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff) 00314 #define ip4_addr2(ipaddr) ((uint16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff) 00315 #define ip4_addr3(ipaddr) ((uint16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff) 00316 #define ip4_addr4(ipaddr) ((uint16_t)(ntohl((ipaddr)->addr)) & 0xff) 00317 00318 #else 00319 # include <lwip/ip_addr.h> 00320 #endif /* WLP_STACK_LWIP */ 00321 00322 00328 struct wlp_network { 00329 struct wlp_ssid ssid; 00330 uint8_t auth; 00331 uint8_t channel; 00332 uint8_t type; 00333 00334 struct wlp_mac_addr bssid; 00335 int16_t rssi; 00337 int16_t snr; 00339 } OWL_PACKED; 00340 00341 #include <wlp_trampoline.h> 00342 00352 #if WLP_STACK_OFFLOAD 00353 00354 /* XXX: wlp_init() for SPB8xx devices should be updated to have the same 00355 interface as wlp_init() for SPB4xxxx devices. Until then we separate them 00356 with WLP_STACK_OFFLOAD since offloaded stack is only used on SPB8xx */ 00357 00406 int wlp_init(int interface, 00407 int (*readf)(void *ctx, void *data, int len), 00408 int (*writef)(void *ctx, const void *data, int len), 00409 void (*selectf)(void *ctx, int select), 00410 void *ctx); 00411 00412 #else 00413 00432 int wlp_init(int (*bus_f)(void *ctx, const void *tx, void *rx, int len), 00433 void (*select_f)(void *ctx, int select), 00434 void (*irqen_f)(void *ctx, int enable), 00435 void (*firmware_f)(void *ctx, int enable), 00436 void *ctx, 00437 int flags); 00438 #endif /* WLP_STACK_OFFLOAD XXX */ 00439 00440 00441 00460 void wlp_set_yield_cb(void (*yieldf)(void *ctx), void *ctx); 00461 00462 00476 void wlp_irq(void); 00477 00478 00546 int wlp_set_baudrate(uint32_t baudrate, uint8_t rtscts); 00547 00548 00549 #if WLP_STACK_OFFLOAD 00550 00568 int wlp_fw_upgrade(uint8_t method, 00569 struct ip_addr *addr, 00570 uint16_t port, 00571 const char *path); 00572 00586 int wlp_set_fw_upgrade_cb(void (*status_cb)(void *ctx, uint8_t success), 00587 void *ctx); 00588 00589 00590 #endif /* WLP_STACK_OFFLOAD */ 00591 00626 int wlp_get_fw_version(uint32_t *code, 00627 char *build, 00628 int build_len, 00629 char *hw_rev, 00630 int hw_rev_len); 00631 00672 int wlp_get_fw_caps(uint8_t *cap_flags); 00673 00674 00675 00708 int wlp_scan(struct wlp_ssid *ssid, 00709 void (*scan_cb)(void *ctx, struct wlp_network *net), void *ctx); 00710 00741 void wlp_set_link_cb(void (*link_cb)(void *ctx, int link), void *ctx); 00742 00743 00806 int wlp_linkup(struct wlp_ssid *ssid, const char *key, enum wlp_auth_mode auth); 00807 00808 00836 int wlp_linkdown(void); 00837 00838 00852 int wlp_set_wps(int enable); 00853 00854 00866 int wlp_get_hwaddr(struct wlp_mac_addr *hwaddr); 00867 00868 00891 int wlp_get_network(struct wlp_network *net); 00892 00893 00900 int wlp_get_link_context(void (*linkctx_cb)(void *ctx, void *linkctx, int len), 00901 void *ctx); 00902 00903 00909 int wlp_set_link_context(void *linkctx); 00910 00911 00912 00916 #if WLP_STACK_OFFLOAD 00917 00956 void wlp_set_ipaddr_cb(void (*addr_cb)(void *ctx, const struct ip_addr *addr), 00957 void *ctx); 00958 00959 00979 int wlp_set_ipaddr(const struct ip_addr *ip, const struct ip_addr *netmask, 00980 const struct ip_addr *gw, const struct ip_addr *dns); 00981 00982 01006 int wlp_get_ipaddr(struct ip_addr *ip, struct ip_addr *netmask, 01007 struct ip_addr *gw, struct ip_addr *dns); 01008 01009 01034 int wlp_set_dhcp(int enable); 01035 01036 01053 int wlp_get_dhcp(int *enabled); 01054 01055 01092 int wlp_set_dhcpd(int enable); 01093 01094 01160 int wlp_socket(int type, int proto); 01161 01162 01193 int wlp_set_conn_cb(int sockid, 01194 void (*conn_cb)(void *ctx, int sockid, int connected), 01195 void *ctx); 01196 01221 int wlp_set_recv_cb(int sockid, 01222 void (*recv_cb)(void *ctx, int sockid, int len), 01223 void *ctx); 01224 01225 int wlp_set_sent_cb(int sockid, 01226 void (*sent_cb)(void *ctx, int sockid, int len), 01227 void *ctx); 01228 01229 01273 int wlp_bind(int sockid, const struct ip_addr *addr, uint16_t port); 01274 01275 01313 int wlp_listen(int sockid, int backlog, 01314 void (*listen_cb)(void *ctx, int sockid), 01315 void *ctx); 01316 01375 int wlp_connect(int sockid, const struct ip_addr *ip, uint16_t port); 01376 01409 int wlp_accept(int sockid); 01410 01411 01431 int wlp_close(int sockid); 01432 01433 01507 int wlp_recv(int sockid, char *buf, int16_t len); 01508 01509 01572 int wlp_send(int sockid, const char *buf, int16_t len); 01573 01574 01614 int wlp_sendto(int sockid, const char *buf, int16_t len, 01615 const struct ip_addr *ip, uint16_t port); 01616 01617 01637 int wlp_get_peeraddr(int sockid, struct ip_addr *peer); 01638 01663 int wlp_get_hostbyname(const char *host, 01664 void (*lookup_cb)(void *ctx, const struct ip_addr *ip), 01665 void *ctx); 01666 01667 #endif /* WLP_STACK_OFFLOAD */ 01668 01695 int wlp_poll(void); 01696 01724 int wlp_set_mode(uint8_t mode); 01725 01726 01727 01743 int wlp_get_mode(uint8_t *mode); 01744 01745 01746 01766 int wlp_set_channel(uint8_t channel, 01767 void (*channel_cb)(void *ctx, int status), void *ctx); 01768 01769 01793 int 01794 wlp_conf_ap(int hidden, int beacon_intvl, int inact_tmo, const char *country); 01795 02017 int wlp_set_wakeup_cb(void (*wakeupf)(void *ctx, int enable), 02018 void *ctx); 02019 02034 int wlp_set_ps(int enable); 02035 02092 int wlp_conf_ps(uint8_t use_ps_poll, 02093 uint32_t ps_traffic_timeout, 02094 uint32_t ps_delay, 02095 uint8_t rx_all_dtim, 02096 uint16_t listen_interval); 02097 02098 02127 int wlp_set_heartbeat(uint32_t ms_period); 02128 02148 int wlp_set_led(int enable); 02149 02181 int wlp_set_poll_period(uint32_t ms_period); 02182 02183 02186 #endif /* WLP_API_H */