Mistake on this page?
Report an issue in GitHub or email us
mx_wifi_ipc.h
Go to the documentation of this file.
1 /**
2  ******************************************************************************
3  * @file mx_wifi_ipc.h
4  * @author MCD Application Team
5  * @brief Header for mx_wifi_ipc.c module
6  ******************************************************************************
7  * @attention
8  *
9  * Copyright (c) 2021 STMicroelectronics.
10  * All rights reserved.
11  *
12  * This software is licensed under terms that can be found in the LICENSE file
13  * in the root directory of this software component.
14  * If no LICENSE file comes with this software, it is provided AS-IS.
15  *
16  ******************************************************************************
17  */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef MX_WIFI_IPC_H
21 #define MX_WIFI_IPC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 /* Includes ------------------------------------------------------------------*/
28 /*cstat -MISRAC2012-* */
29 #include <stdint.h>
30 #include <string.h>
31 #include <stdbool.h>
32 #include <stdio.h>
33 /*cstat +MISRAC2012-* */
34 
35 #include "mx_wifi.h"
36 
37 /* Exported Constants --------------------------------------------------------*/
38 /* #define MX_WIFI_IPC_DEBUG */
39 #define MX_API_VERSION ("2.0.0")
40 
41 /**
42  * @brief IPC error code
43  */
44 #define MIPC_CODE_SUCCESS (0)
45 #define MIPC_CODE_ERROR (-1)
46 #define MIPC_CODE_TIMEOUT (-2)
47 #define MIPC_CODE_NO_MEMORY (-3)
48 
49 /**
50  * @brief IPC packet
51  */
52 /*
53  * |--------+--------+--------------------|
54  * | req_id | api_id | args (<p1>...<pn>) |
55  * |--------+--------+--------------------|
56  * | 4Bytes | 2Btyes | nBytes |
57  * |--------+--------+--------------------|
58  */
59 #define MIPC_PKT_REQ_ID_OFFSET (0)
60 #define MIPC_PKT_REQ_ID_SIZE (4)
61 #define MIPC_PKT_API_ID_OFFSET (MIPC_PKT_REQ_ID_OFFSET + MIPC_PKT_REQ_ID_SIZE)
62 #define MIPC_PKT_API_ID_SIZE (2)
63 #define MIPC_PKT_PARAMS_OFFSET (MIPC_PKT_API_ID_OFFSET + MIPC_PKT_API_ID_SIZE)
64 #define MIPC_HEADER_SIZE (MIPC_PKT_REQ_ID_SIZE + MIPC_PKT_API_ID_SIZE)
65 #define MIPC_PKT_MIN_SIZE (MIPC_HEADER_SIZE)
66 #define MIPC_PKT_MAX_SIZE (MIPC_HEADER_SIZE + MX_WIFI_IPC_PAYLOAD_SIZE)
67 
68 /**
69  * @brief IPC api id
70  */
71 #define MIPC_REQ_ID_NONE (0x00000000)
72 #define MIPC_API_ID_NONE (0x0000)
73 #define MIPC_API_CMD_BASE (MIPC_API_ID_NONE)
74 #define MIPC_API_EVENT_BASE (0x8000)
75 
76 /**
77  * API CMD
78  */
79 /* system */
80 #define MIPC_API_SYS_CMD_BASE (MIPC_API_CMD_BASE + 0x0000)
81 #define MIPC_API_SYS_ECHO_CMD (MIPC_API_SYS_CMD_BASE + 0x0001)
82 #define MIPC_API_SYS_REBOOT_CMD (MIPC_API_SYS_CMD_BASE + 0x0002)
83 #define MIPC_API_SYS_VERSION_CMD (MIPC_API_SYS_CMD_BASE + 0x0003)
84 #define MIPC_API_SYS_RESET_CMD (MIPC_API_SYS_CMD_BASE + 0x0004)
85 
86 /* wifi */
87 #define MIPC_API_WIFI_CMD_BASE (MIPC_API_CMD_BASE + 0x0100)
88 #define MIPC_API_WIFI_GET_MAC_CMD (MIPC_API_WIFI_CMD_BASE + 0x0001)
89 #define MIPC_API_WIFI_SCAN_CMD (MIPC_API_WIFI_CMD_BASE + 0x0002)
90 #define MIPC_API_WIFI_CONNECT_CMD (MIPC_API_WIFI_CMD_BASE + 0x0003)
91 #define MIPC_API_WIFI_DISCONNECT_CMD (MIPC_API_WIFI_CMD_BASE + 0x0004)
92 #define MIPC_API_WIFI_SOFTAP_START_CMD (MIPC_API_WIFI_CMD_BASE + 0x0005)
93 #define MIPC_API_WIFI_SOFTAP_STOP_CMD (MIPC_API_WIFI_CMD_BASE + 0x0006)
94 #define MIPC_API_WIFI_GET_IP_CMD (MIPC_API_WIFI_CMD_BASE + 0x0007)
95 #define MIPC_API_WIFI_GET_LINKINFO_CMD (MIPC_API_WIFI_CMD_BASE + 0x0008)
96 #define MIPC_API_WIFI_PS_ON_CMD (MIPC_API_WIFI_CMD_BASE + 0x0009)
97 #define MIPC_API_WIFI_PS_OFF_CMD (MIPC_API_WIFI_CMD_BASE + 0x000a)
98 #define MIPC_API_WIFI_PING_CMD (MIPC_API_WIFI_CMD_BASE + 0x000b)
99 #define MIPC_API_WIFI_BYPASS_SET_CMD (MIPC_API_WIFI_CMD_BASE + 0x000c)
100 #define MIPC_API_WIFI_BYPASS_GET_CMD (MIPC_API_WIFI_CMD_BASE + 0x000d)
101 #define MIPC_API_WIFI_BYPASS_OUT_CMD (MIPC_API_WIFI_CMD_BASE + 0x000e)
102 
103 /* socket */
104 #define MIPC_API_SOCKET_CMD_BASE (MIPC_API_CMD_BASE + 0x0200)
105 #define MIPC_API_SOCKET_CREATE_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0001)
106 #define MIPC_API_SOCKET_CONNECT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0002)
107 #define MIPC_API_SOCKET_SEND_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0003)
108 #define MIPC_API_SOCKET_SENDTO_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0004)
109 #define MIPC_API_SOCKET_RECV_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0005)
110 #define MIPC_API_SOCKET_RECVFROM_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0006)
111 #define MIPC_API_SOCKET_SHUTDOWN_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0007)
112 #define MIPC_API_SOCKET_CLOSE_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0008)
113 #define MIPC_API_SOCKET_GETSOCKOPT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0009)
114 #define MIPC_API_SOCKET_SETSOCKOPT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x000a)
115 #define MIPC_API_SOCKET_BIND_CMD (MIPC_API_SOCKET_CMD_BASE + 0x000b)
116 #define MIPC_API_SOCKET_LISTEN_CMD (MIPC_API_SOCKET_CMD_BASE + 0x000c)
117 #define MIPC_API_SOCKET_ACCEPT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x000d)
118 #define MIPC_API_SOCKET_SELECT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x000e)
119 #define MIPC_API_SOCKET_GETSOCKNAME_CMD (MIPC_API_SOCKET_CMD_BASE + 0x000f)
120 #define MIPC_API_SOCKET_GETPEERNAME_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0010)
121 #define MIPC_API_SOCKET_GETHOSTBYNAME_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0011)
122 
123 /* TLS cmd */
124 #define MIPC_API_TLS_SET_VER_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0081)
125 #define MIPC_API_TLS_SET_CLIENT_CERT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0082)
126 #define MIPC_API_TLS_SET_SERVER_CERT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0083)
127 #define MIPC_API_TLS_ACCEPT_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0084)
128 #define MIPC_API_TLS_CONNECT_SNI_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0085)
129 #define MIPC_API_TLS_SEND_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0086)
130 #define MIPC_API_TLS_RECV_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0087)
131 #define MIPC_API_TLS_CLOSE_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0088)
132 #define MIPC_API_TLS_SET_NONBLOCK_CMD (MIPC_API_SOCKET_CMD_BASE + 0x0089)
133 
134 #define MIPC_API_MDNS_CMD_BASE (MIPC_API_CMD_BASE + 0x0300)
135 #define MIPC_API_MDNS_START_CMD (MIPC_API_MDNS_CMD_BASE + 0x0001)
136 #define MIPC_API_MDNS_STOP_CMD (MIPC_API_MDNS_CMD_BASE + 0x0002)
137 #define MIPC_API_MDNS_ANNOUNCE_CMD (MIPC_API_MDNS_CMD_BASE + 0x0003)
138 #define MIPC_API_MDNS_DEANNOUNCE_CMD (MIPC_API_MDNS_CMD_BASE + 0x0004)
139 #define MIPC_API_MDNS_DEANNOUNCE_ALL_CMD (MIPC_API_MDNS_CMD_BASE + 0x0005)
140 #define MIPC_API_MDNS_IFACE_STATE_CHANGE_CMD (MIPC_API_MDNS_CMD_BASE + 0x0006)
141 #define MIPC_API_MDNS_SET_HOSTNAME_CMD (MIPC_API_MDNS_CMD_BASE + 0x0007)
142 #define MIPC_API_MDNS_SET_TXT_REC_CMD (MIPC_API_MDNS_CMD_BASE + 0x0008)
143 /**
144  * API EVENT
145  */
146 /* system */
147 #define MIPC_API_SYS_EVENT_BASE (MIPC_API_EVENT_BASE + 0x0000)
148 #define MIPC_API_SYS_REBOOT_EVENT (MIPC_API_SYS_EVENT_BASE + 0x0001)
149 
150 /* wifi */
151 #define MIPC_API_WIFI_EVENT_BASE (MIPC_API_EVENT_BASE + 0x0100)
152 #define MIPC_API_WIFI_STATUS_EVENT (MIPC_API_WIFI_EVENT_BASE + 0x0001)
153 #define MIPC_API_WIFI_BYPASS_INPUT_EVENT (MIPC_API_WIFI_EVENT_BASE + 0x0002)
154 
155 /* Exported macro-------------------------------------------------------------*/
156 
157 /* Exported typedef ----------------------------------------------------------*/
158 typedef uint16_t (*mipc_send_func_t)(uint8_t *data, uint16_t size);
159 
160 /* Exported functions --------------------------------------------------------*/
161 
162 /* MX_IPC */
163 int32_t mipc_init(mipc_send_func_t ipc_send);
164 int32_t mipc_deinit(void);
165 
166 /* ipc api request */
167 int32_t mipc_request(uint16_t api_id, uint8_t *cparams, uint16_t cparams_size,
168  uint8_t *rbuffer, uint16_t *rbuffer_size, uint32_t timeout_ms);
169 
170 /* ipc handle response/event */
171 void mipc_poll(uint32_t timeout);
172 
173 /* ipc echo test */
174 int32_t mipc_echo(uint8_t *in, uint16_t in_len, uint8_t *out, uint16_t *out_len,
175  uint32_t timeout);
176 
177 /* Module API event callbacks ------------------------------------------------*/
178 /* system */
179 void mapi_reboot_event_callback(mx_buf_t *buff);
180 
181 /* wifi */
182 #pragma pack(1)
183 typedef struct _wifi_scan_cparams_s
184 {
185  int8_t ssid[33]; /* 32 + 1 '\0' string end */
187 
188 typedef struct _wifi_scan_rparams_s
189 {
190  uint8_t num;
191  mwifi_ap_info_t ap[1]; /* ap info array memory */
193 
194 typedef struct
195 {
196  uint8_t bssid[6]; /**< bssid of access-point */
197  uint8_t channel; /**< channel of access-point */
198  mwifi_security_t security; /**< security of access-point */
200 
202 {
203  int8_t ssid[33]; /* 32 + 1 '\0' string end */
204  int8_t key[65]; /* 64 + 1 '\0' string end */
205  int32_t key_len;
206  uint8_t use_attr;
207  uint8_t use_ip;
209  mwifi_ip_attr_t ip;
211 
212 typedef struct
213 {
214  int32_t is_connected; /**< The link to wlan is established or not, 0: disconnected, 1: connected. */
215  int32_t rssi; /**< Signal strength of the current connected AP */
216  int8_t ssid[33]; /**< SSID of the current connected wlan */
217  uint8_t bssid[6]; /**< BSSID of the current connected wlan */
218  int8_t key[65]; /**< The passphrase/PSK of the connected AP */
219  int32_t channel; /**< Channel of the current connected wlan */
220  mwifi_security_t security; /**< security of access-point */
222 
224 {
225  int32_t status;
228 
230 {
231  int32_t status;
232  mwifi_ip_attr_t ip;
234 
236 {
237  int8_t ssid[32];
238  int8_t key[64];
239  int32_t channel;
240  mwifi_ip_attr_t ip;
242 
243 /* ping */
244 typedef struct wifi_ping_cparams_s
245 {
246  char hostname[255];
247  int32_t count;
248  int32_t delay_ms;
250 
251 typedef struct wifi_ping_rparams_s
252 {
253  int32_t num;
254  int32_t delay_ms[1];
256 
258 {
259  int32_t mode;
261 
263 {
264  int32_t mode;
266 
268 {
269  int32_t idx;
270  uint8_t useless[16];
271  uint16_t data_len;
273 
275 {
276  int32_t idx;
277  uint8_t useless[16];
278  uint16_t tot_len;
280 #pragma pack()
281 
282 void mapi_wifi_status_event_callback(mx_buf_t *nbuf);
283 void mapi_wifi_netlink_input_callback(mx_buf_t *nbuf);
284 
285 
286 #if MX_WIFI_NETWORK_BYPASS_MODE == 0
287 /* socket */
288 #pragma pack(1)
289 /* create */
291 {
292  int32_t domain;
293  int32_t type;
294  int32_t protocol;
296 
298 {
299  int32_t fd;
301 
302 /* setsockopt */
304 {
305  int32_t socket;
306  int32_t level;
307  int32_t optname;
308  socklen_t optlen;
309  uint8_t optval[16];
311 
313 {
314  int32_t status;
316 
317 /* getsockopt */
319 {
320  int32_t socket;
321  int32_t level;
322  int32_t optname;
324 
326 {
327  int32_t status;
328  socklen_t optlen;
329  uint8_t optval[16];
331 
332 /* bind */
334 {
335  int32_t socket;
336  struct sockaddr addr;
337  socklen_t length;
339 
341 {
342  int32_t status;
344 
345 /* connect */
347 {
348  int32_t socket;
349  struct sockaddr addr;
350  socklen_t length;
352 
354 {
355  int32_t status;
357 
358 /* shutdown */
360 {
361  int32_t filedes;
362  int32_t how;
364 
366 {
367  int32_t status;
369 
370 /* close */
372 {
373  int32_t filedes;
375 
377 {
378  int32_t status;
380 
381 /* send */
383 {
384  int32_t socket;
385  size_t size;
386  int32_t flags;
387  uint8_t buffer[1];
389 
391 {
392  int32_t sent;
394 
395 /* sendto */
397 {
398  int32_t socket;
399  size_t size;
400  int32_t flags;
401  struct sockaddr addr;
402  socklen_t length;
403  uint8_t buffer[1];
405 
407 {
408  int32_t sent;
410 
411 /* recv */
413 {
414  int32_t socket;
415  size_t size;
416  int32_t flags;
418 
420 {
421  int32_t received;
422  uint8_t buffer[1];
424 
425 /* recvfrom */
427 {
428  int32_t socket;
429  size_t size;
430  int32_t flags;
432 
434 {
435  int32_t received;
436  struct sockaddr addr;
437  socklen_t length;
438  uint8_t buffer[1];
440 
441 /* gethostbyname */
443 {
444  char name[253];
446 
448 {
449  int32_t status;
450  uint32_t s_addr;
452 
453 /* getpeername */
455 {
456  int32_t s;
458 
460 {
461  int32_t status;
462  struct sockaddr name;
463  socklen_t namelen;
465 
466 /* getsockname */
468 {
469  int32_t s;
471 
473 {
474  int32_t status;
475  struct sockaddr name;
476  socklen_t namelen;
478 
479 /* listen */
481 {
482  int32_t socket;
483  int32_t n;
485 
487 {
488  int32_t status;
490 
491 /* accept */
493 {
494  int32_t socket;
496 
498 {
499  int32_t socket;
500  struct sockaddr addr;
501  socklen_t length;
503 
504 /* tls */
505 /* tls set ver */
507 {
508  mtls_ver_t version;
510 
512 {
513  int32_t ret;
515 
516 /* tls set client cert */
518 {
519  uint16_t cert_pem_size;
520  uint16_t private_key_pem_size;
521  char cert_data[1]; /* cert_pem + private_key_pem */
523 
525 {
526  int32_t ret;
528 
529 /* tls set server cert */
531 {
532  uint16_t cert_pem_size;
533  uint16_t private_key_pem_size;
534  uint16_t verify_ca_size;
535  char cert_data[1]; /* cert_pem + private_key_pem + verify_ca */
537 
539 {
540  int32_t ret;
542 
543 /* tls accept */
544 typedef struct _tls_accept_cparams_s
545 {
546  int32_t fd;
548 
549 typedef struct _tls_accept_rparams_s
550 {
551  mtls_t tls;
553 
554 /* tls connect_sni */
556 {
557  struct sockaddr addr;
558  socklen_t length;
559  char sni_servername[128];
560  int32_t calen;
561  char ca[1];
563 
565 {
566  mtls_t tls;
567  int32_t errno;
569 
570 /* tls send */
571 typedef struct _tls_send_cparams_s
572 {
573  mtls_t tls;
574  size_t size;
575  uint8_t buffer[1];
577 
578 typedef struct _tls_send_rparams_s
579 {
580  int32_t sent;
582 
583 /* tls recv */
584 typedef struct _tls_recv_cparams_s
585 {
586  mtls_t tls;
587  size_t size;
589 
590 typedef struct _tls_recv_rparams_s
591 {
592  int32_t received;
593  uint8_t buffer[1];
595 
596 /* tls close */
597 typedef struct _tls_close_cparams_s
598 {
599  mtls_t tls;
601 
602 typedef struct _tls_close_rparams_s
603 {
604  int32_t ret;
606 
607 /* tls nonblock */
609 {
610  mtls_t tls;
611  int32_t nonblock;
613 
615 {
616  int32_t ret;
618 
619 #pragma pack()
620 
621 #pragma pack(1)
622 typedef struct mdns_start_cparams_s
623 {
624  char domain[MDNS_MAX_LABEL_LEN + 1];
625  char hostname[MDNS_MAX_LABEL_LEN + 1];
628 {
629  uint8_t iface;
630  struct mc_mdns_service service_data;
633 {
634  uint8_t iface;
637 {
638  uint8_t iface;
639  uint8_t state;
642 {
643  char hostname[MDNS_MAX_LABEL_LEN + 1];
646 {
647  struct mc_mdns_service service_data;
648  char keyvals[MDNS_MAX_KEYVAL_LEN + 1];
649  char separator;
651 #pragma pack()
652 #endif /* MX_WIFI_NETWORK_BYPASS_MODE */
653 #ifdef __cplusplus
654 }
655 #endif /* __cplusplus */
656 
657 #endif /* MX_WIFI_IPC_H */
uint8_t mwifi_security_t
Wi-Fi softAP info.
Definition: mx_wifi.h:683
#define MDNS_MAX_KEYVAL_LEN
Maximum length of key/value pair.
Definition: mx_wifi.h:1147
Wi-Fi ip address info.
Definition: mx_wifi.h:84
void * mtls_t
mxchip TLS handler type
Definition: mx_wifi.h:1316
The key size.
mwifi_security_t security
security of access-point
Definition: mx_wifi_ipc.h:198
Header for mx_wifi.c module.
socket address struct
Definition: mx_wifi.h:730
mDNS service info
Definition: mx_wifi.h:1208
uint8_t channel
channel of access-point
Definition: mx_wifi_ipc.h:197
#define MDNS_MAX_LABEL_LEN
Maximum length of labels.
Definition: mx_wifi.h:1133
char keyvals[255 +1]
Key value pairs for TXT records.
Definition: mx_wifi.h:1221
char separator
separator for txt record
Definition: mx_wifi.h:1228
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.