wifi8 2.0.0.0

wifi8.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22
28 #ifndef WIFI8_H
29 #define WIFI8_H
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35
36 #include "drv_digital_out.h"
37 #include "drv_digital_in.h"
38 #include "drv_spi_master.h"
39 #include "wifi8_types.h"
40
61 #define WIFI8_MAP_MIKROBUS(cfg, mikrobus) \
62 cfg.miso = MIKROBUS(mikrobus, MIKROBUS_MISO); \
63 cfg.mosi = MIKROBUS(mikrobus, MIKROBUS_MOSI); \
64 cfg.sck = MIKROBUS(mikrobus, MIKROBUS_SCK); \
65 cfg.cs = MIKROBUS(mikrobus, MIKROBUS_CS); \
66 cfg.en = MIKROBUS(mikrobus, MIKROBUS_AN); \
67 cfg.rst = MIKROBUS(mikrobus, MIKROBUS_RST); \
68 cfg.wkp = MIKROBUS(mikrobus, MIKROBUS_PWM); \
69 cfg.int_pin = MIKROBUS(mikrobus, MIKROBUS_INT)
70 // wifi8_map // wifi8
73
78 typedef struct
79 {
80 // Output pins
81 digital_out_t en;
82 digital_out_t rst;
83 digital_out_t wkp;
85 // Input pins
86 digital_in_t int_pin;
88 // Modules
89 spi_master_t spi;
91 pin_name_t chip_select;
93 uint8_t hif_bl_offset;
94 wifi8_nm_state_t device_state;
95 uint8_t ch_num;
96 uint32_t hs_flags;
97 wifi8_socket_t sockets[MAX_SOCKET];
98 uint8_t root_sha1[20];
99 uint16_t session_id;
100 uint8_t socket_init;
101 uint32_t ping_id;
102 wifi8_app_wifi_cb_t app_wifi_cb;
103 wifi8_app_socket_cb_t app_socket_cb;
104 wifi8_app_resolve_cb_t app_resolve_cb;
105 wifi8_ping_cb_t ping_cb;
106
107 } wifi8_t;
108
113 typedef struct
114 {
115 // Communication gpio pins
116 pin_name_t miso;
117 pin_name_t mosi;
118 pin_name_t sck;
119 pin_name_t cs;
121 // Additional gpio pins
122 pin_name_t en;
123 pin_name_t rst;
124 pin_name_t wkp;
125 pin_name_t int_pin;
127 // static variable
128 uint32_t spi_speed;
129 spi_master_mode_t spi_mode;
130 spi_master_chip_select_polarity_t cs_polarity;
132 } wifi8_cfg_t;
133
134 typedef void (*wifi8_hif_call_back_t)(wifi8_t *ctx, uint8_t u8_op_code, uint16_t u16_data_size, uint32_t u32_addr);
135 typedef wifi8_sock_addr_t wifi8_uip_sock_addr_t;
136
137 typedef struct
138 {
139 uint8_t u8_chip_mode;
140 uint8_t u8_chip_sleep;
141 uint8_t u8_hif_rx_done;
142 uint8_t u8_interrupt;
143 uint8_t u8_yield;
144 uint32_t u32_rx_addr;
145 uint32_t u32_rx_size;
146 wifi8_hif_call_back_t pf_wifi_cb;
147 wifi8_hif_call_back_t pf_ip_cb;
148 wifi8_hif_call_back_t pf_ota_cb;
149 wifi8_hif_call_back_t pf_sigma_cb;
150 wifi8_hif_call_back_t pf_hif_cb;
151 wifi8_hif_call_back_t pf_crypto_cb;
152 wifi8_hif_call_back_t pf_ssl_cb;
153 } wifi8_hif_context_t;
154
170 void wifi8_cfg_setup(wifi8_cfg_t *cfg);
171
185 err_t wifi8_init(wifi8_t *ctx, wifi8_cfg_t *cfg);
186
200 err_t wifi8_default_cfg(wifi8_t *ctx);
201
216 err_t wifi8_generic_write(wifi8_t *ctx, uint8_t *data_in, uint8_t len);
217
232 err_t wifi8_generic_read(wifi8_t *ctx, uint8_t *data_out, uint8_t len);
233
248 err_t wifi8_reg_write(wifi8_t *ctx, uint32_t addr, uint32_t data_in);
249
264 err_t wifi8_reg_read(wifi8_t *ctx, uint32_t addr, uint32_t *data_out);
265
281 err_t wifi8_block_read(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len);
282
298 err_t wifi8_block_write(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len);
299
314 err_t wifi8_init_drv(wifi8_t *ctx);
315
323 uint32_t wifi8_chip_id(wifi8_t *ctx);
324
336 err_t wifi8_get_full_firmware_version(wifi8_t *ctx, wifi8_m2m_rev_t *fw_version);
337
350 err_t wifi8_get_ota_firmware_version(wifi8_t *ctx, wifi8_m2m_rev_t *fw_version);
351
367 err_t wifi8_connect(wifi8_t *ctx, char *pc_ssid, uint8_t u8_ssid_len, wifi8_m2m_sec_type_t u8_sec_type, void *pv_auth_info, uint16_t u16_ch);
368
382 err_t wifi8_get_connection_info(wifi8_t *ctx);
383
397 err_t wifi8_start_ap(wifi8_t *ctx, wifi8_m2m_ap_config_t *pstr_m2m_ap_config);
398
415 err_t wifi8_req_scan_result(wifi8_t *ctx, uint8_t scan_request_index);
416
431 err_t wifi8_request_scan(wifi8_t *ctx, uint8_t channel);
432
445 err_t wifi8_handle_events(wifi8_t *ctx);
446
459 err_t wifi8_ble_api_send(wifi8_t *ctx, uint8_t *msg, uint32_t len);
460
475 void wifi8_socket_init(wifi8_t *ctx);
476
491 err_t wifi8_socket_create(wifi8_t *ctx, uint16_t u16_domain, uint8_t u8_type, uint8_t u8_flags);
492
508 err_t wifi8_socket_bind(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len);
509
526 int8_t wifi8_socket_listen(wifi8_t *ctx, int8_t sock, uint8_t backlog);
527
544 err_t wifi8_socket_connect(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len);
545
561 err_t wifi8_socket_send(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length);
562
580 err_t wifi8_socket_send_to(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length, wifi8_sockaddr_t *pstr_dest_addr, uint8_t u8_addr_len);
581
600 err_t wifi8_socket_receive(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec);
601
618 err_t wifi8_socket_receive_from(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec);
619
631 err_t wifi8_socket_close(wifi8_t *ctx, int8_t sock);
632
633 #ifdef __cplusplus
634 }
635 #endif
636 #endif // WIFI8_H
637 // wifi8
639
640 // ------------------------------------------------------------------------ END
wifi8_nm_state_t
wifi8_nm_state_t
Definition: wifi8_types.h:618
wifi8_cfg_t::cs
pin_name_t cs
Definition: wifi8.h:119
wifi8_block_write
err_t wifi8_block_write(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len)
Write blocks of data to register address.
wifi8_t::app_wifi_cb
wifi8_app_wifi_cb_t app_wifi_cb
Definition: wifi8.h:102
wifi8_get_full_firmware_version
err_t wifi8_get_full_firmware_version(wifi8_t *ctx, wifi8_m2m_rev_t *fw_version)
Synchronous API to obtain the firmware version currently running on the device.
wifi8_sock_addr_t
Definition: wifi8_types.h:848
wifi8_init
err_t wifi8_init(wifi8_t *ctx, wifi8_cfg_t *cfg)
WiFi 8 initialization function.
wifi8_t
WiFi 8 Click context object.
Definition: wifi8.h:79
wifi8_reg_write
err_t wifi8_reg_write(wifi8_t *ctx, uint32_t addr, uint32_t data_in)
Write data to register address.
wifi8_hif_context_t::pf_hif_cb
wifi8_hif_call_back_t pf_hif_cb
Definition: wifi8.h:150
wifi8_hif_context_t::pf_ip_cb
wifi8_hif_call_back_t pf_ip_cb
Definition: wifi8.h:147
wifi8_hif_context_t::u8_yield
uint8_t u8_yield
Definition: wifi8.h:143
wifi8_init_drv
err_t wifi8_init_drv(wifi8_t *ctx)
Synchronous API to initialize the device driver.
wifi8_sockaddr_t
Definition: wifi8_types.h:772
wifi8_cfg_t
WiFi 8 Click configuration object.
Definition: wifi8.h:114
wifi8_hif_context_t
Definition: wifi8.h:138
wifi8_hif_context_t::u32_rx_size
uint32_t u32_rx_size
Definition: wifi8.h:145
wifi8_m2m_ap_config_t
Definition: wifi8_types.h:816
wifi8_uip_sock_addr_t
wifi8_sock_addr_t wifi8_uip_sock_addr_t
Definition: wifi8.h:135
wifi8_socket_init
void wifi8_socket_init(wifi8_t *ctx)
The function performs the necessary initializations for the socket library.
wifi8_socket_receive_from
err_t wifi8_socket_receive_from(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec)
Asynchronous receive function.
wifi8_cfg_t::en
pin_name_t en
Definition: wifi8.h:122
wifi8_hif_context_t::u8_chip_mode
uint8_t u8_chip_mode
Definition: wifi8.h:139
wifi8_t::int_pin
digital_in_t int_pin
Definition: wifi8.h:86
wifi8_t::rst
digital_out_t rst
Definition: wifi8.h:82
wifi8_hif_context_t::u32_rx_addr
uint32_t u32_rx_addr
Definition: wifi8.h:144
wifi8_socket_send_to
err_t wifi8_socket_send_to(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length, wifi8_sockaddr_t *pstr_dest_addr, uint8_t u8_addr_len)
Asynchronous sending function.
wifi8_t::session_id
uint16_t session_id
Definition: wifi8.h:99
wifi8_hif_context_t::u8_hif_rx_done
uint8_t u8_hif_rx_done
Definition: wifi8.h:141
addr
wifi8_sockaddr_in_t addr
Definition: main.c:62
wifi8_app_socket_cb_t
void(* wifi8_app_socket_cb_t)(int8_t sock, uint8_t u8_msg, void *pv_msg)
Definition: wifi8_types.h:1333
wifi8_socket_listen
int8_t wifi8_socket_listen(wifi8_t *ctx, int8_t sock, uint8_t backlog)
Asynchronous listen function.
wifi8_cfg_setup
void wifi8_cfg_setup(wifi8_cfg_t *cfg)
WiFi 8 configuration object setup function.
wifi8_hif_context_t::pf_ssl_cb
wifi8_hif_call_back_t pf_ssl_cb
Definition: wifi8.h:152
wifi8_types.h
wifi8_cfg_t::sck
pin_name_t sck
Definition: wifi8.h:118
wifi8_cfg_t::rst
pin_name_t rst
Definition: wifi8.h:123
wifi8_cfg_t::miso
pin_name_t miso
Definition: wifi8.h:116
wifi8_hif_context_t::pf_ota_cb
wifi8_hif_call_back_t pf_ota_cb
Definition: wifi8.h:148
wifi8_t::hs_flags
uint32_t hs_flags
Definition: wifi8.h:96
wifi8_t::hif_bl_offset
uint8_t hif_bl_offset
Definition: wifi8.h:93
wifi8_t::ping_id
uint32_t ping_id
Definition: wifi8.h:101
wifi8_get_connection_info
err_t wifi8_get_connection_info(wifi8_t *ctx)
wifi8_handle_events
err_t wifi8_handle_events(wifi8_t *ctx)
Synchronous event handler function.
wifi8_block_read
err_t wifi8_block_read(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len)
Read blocks of data from register address.
wifi8_t::socket_init
uint8_t socket_init
Definition: wifi8.h:100
wifi8_socket_connect
err_t wifi8_socket_connect(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len)
Asynchronous connect function.
wifi8_t::en
digital_out_t en
Definition: wifi8.h:81
wifi8_cfg_t::spi_speed
uint32_t spi_speed
Definition: wifi8.h:128
wifi8_ble_api_send
err_t wifi8_ble_api_send(wifi8_t *ctx, uint8_t *msg, uint32_t len)
Asynchronous API to send an encapsulated BLE message.
wifi8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: wifi8.h:130
wifi8_hif_context_t::pf_crypto_cb
wifi8_hif_call_back_t pf_crypto_cb
Definition: wifi8.h:151
wifi8_ping_cb_t
void(* wifi8_ping_cb_t)(uint32_t u32ip_addr, uint32_t u32rtt, uint8_t u8_error_code)
Definition: wifi8_types.h:1335
wifi8_hif_context_t::pf_sigma_cb
wifi8_hif_call_back_t pf_sigma_cb
Definition: wifi8.h:149
wifi8_hif_call_back_t
void(* wifi8_hif_call_back_t)(wifi8_t *ctx, uint8_t u8_op_code, uint16_t u16_data_size, uint32_t u32_addr)
Definition: wifi8.h:134
wifi8_t::device_state
wifi8_nm_state_t device_state
Definition: wifi8.h:94
wifi8_t::app_resolve_cb
wifi8_app_resolve_cb_t app_resolve_cb
Definition: wifi8.h:104
wifi8_app_resolve_cb_t
void(* wifi8_app_resolve_cb_t)(uint8_t *pu8_domain_name, uint32_t u32_server_ip)
Definition: wifi8_types.h:1334
wifi8_cfg_t::mosi
pin_name_t mosi
Definition: wifi8.h:117
wifi8_generic_read
err_t wifi8_generic_read(wifi8_t *ctx, uint8_t *data_out, uint8_t len)
Generic reading function.
wifi8_socket_t
Definition: wifi8_types.h:975
wifi8_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: wifi8.h:129
wifi8_socket_bind
err_t wifi8_socket_bind(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len)
Asynchronous bind function associates the provided address and local port to the socket.
wifi8_generic_write
err_t wifi8_generic_write(wifi8_t *ctx, uint8_t *data_in, uint8_t len)
Generic writing function.
wifi8_m2m_rev_t
Definition: wifi8_types.h:837
wifi8_cfg_t::int_pin
pin_name_t int_pin
Definition: wifi8.h:125
MAX_SOCKET
#define MAX_SOCKET
Definition: wifi8_types.h:179
wifi8_cfg_t::wkp
pin_name_t wkp
Definition: wifi8.h:124
wifi8_m2m_sec_type_t
wifi8_m2m_sec_type_t
Definition: wifi8_types.h:430
wifi8_t::ping_cb
wifi8_ping_cb_t ping_cb
Definition: wifi8.h:105
wifi8_t::chip_select
pin_name_t chip_select
Definition: wifi8.h:91
wifi8_default_cfg
err_t wifi8_default_cfg(wifi8_t *ctx)
WiFi 8 default configuration function.
wifi8_get_ota_firmware_version
err_t wifi8_get_ota_firmware_version(wifi8_t *ctx, wifi8_m2m_rev_t *fw_version)
Synchronous API to obtain the firmware version of the device.
wifi8_connect
err_t wifi8_connect(wifi8_t *ctx, char *pc_ssid, uint8_t u8_ssid_len, wifi8_m2m_sec_type_t u8_sec_type, void *pv_auth_info, uint16_t u16_ch)
wifi8_hif_context_t::pf_wifi_cb
wifi8_hif_call_back_t pf_wifi_cb
Definition: wifi8.h:146
wifi8_socket_receive
err_t wifi8_socket_receive(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec)
Asynchronous receive function.
wifi8_chip_id
uint32_t wifi8_chip_id(wifi8_t *ctx)
Get device ID.
wifi8_t::ch_num
uint8_t ch_num
Definition: wifi8.h:95
wifi8_start_ap
err_t wifi8_start_ap(wifi8_t *ctx, wifi8_m2m_ap_config_t *pstr_m2m_ap_config)
Asynchronous API to enable access point (AKA "hot-spot") mode on the device.
wifi8_socket_create
err_t wifi8_socket_create(wifi8_t *ctx, uint16_t u16_domain, uint8_t u8_type, uint8_t u8_flags)
Synchronous socket allocation function based on the specified socket type.
wifi8_app_wifi_cb_t
void(* wifi8_app_wifi_cb_t)(uint8_t u8_msg_type, void *pv_msg)
Definition: wifi8_types.h:1331
wifi8_t::wkp
digital_out_t wkp
Definition: wifi8.h:83
wifi8_t::spi
spi_master_t spi
Definition: wifi8.h:89
wifi8_socket_close
err_t wifi8_socket_close(wifi8_t *ctx, int8_t sock)
Synchronous close function.
wifi8_hif_context_t::u8_chip_sleep
uint8_t u8_chip_sleep
Definition: wifi8.h:140
wifi8_hif_context_t::u8_interrupt
uint8_t u8_interrupt
Definition: wifi8.h:142
wifi8_socket_send
err_t wifi8_socket_send(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length)
Asynchronous sending function.
wifi8_t::app_socket_cb
wifi8_app_socket_cb_t app_socket_cb
Definition: wifi8.h:103
wifi8_req_scan_result
err_t wifi8_req_scan_result(wifi8_t *ctx, uint8_t scan_request_index)
Asynchronous API to request the information of an access point discovered via scanning.
wifi8_reg_read
err_t wifi8_reg_read(wifi8_t *ctx, uint32_t addr, uint32_t *data_out)
Read data from register address.
wifi8_request_scan
err_t wifi8_request_scan(wifi8_t *ctx, uint8_t channel)
Asynchronous API to request the WINC to scan for networks.