Morse Micro IoT SDK  2.9.7
m2m_controller.c
Go to the documentation of this file.
1/*
2 * Copyright 2024 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
164#include "mmhal.h"
165#include "mmosal.h"
166#include "mmutils.h"
167#include "mmagic_controller.h"
168
169/* Default SSID */
170#ifndef SSID
172#define SSID MorseMicro
173#endif
174
175/* Default passphrase */
176#ifndef SAE_PASSPHRASE
179#define SAE_PASSPHRASE 12345678
180#endif
181
183#define _STRINGIFY(x) #x
185#define STRINGIFY(x) _STRINGIFY(x)
186
188#define LINK_STATE_TIMEOUT_MS 20000
189
191#define TCP_ECHCO_SERVER_PORT 5000
192
199void agent_start_handler(struct mmagic_controller *controller, void *arg)
200{
201 MM_UNUSED(controller);
202 struct mmosal_semb *started = (struct mmosal_semb *)arg;
203 printf("Agent start notification received\n");
204 mmosal_semb_give(started);
205}
206
208static struct mmosal_semb *agent_started_semb = NULL;
209
218static bool wlan_connect(struct mmagic_controller *controller)
219{
220 printf("\n\n#### Example WLAN Connect using MMAGIC Controller ####\n\n");
221 enum mmagic_status status;
222
223 printf("Attempting to connect to %s with passphrase %s\n", STRINGIFY(SSID),
225 printf("This may take some time (~10 seconds)\n");
226 status = mmagic_controller_set_wlan_ssid(controller, STRINGIFY(SSID));
227 if (status != MMAGIC_STATUS_OK)
228 {
229 printf("Error %d setting the wlan ssid\n", status);
230 return false;
231 }
232
234 if (status != MMAGIC_STATUS_OK)
235 {
236 printf("Error %d setting the wlan password\n", status);
237 return false;
238 }
239
240 struct mmagic_core_wlan_connect_cmd_args connect_args = {
241 .timeout = 120000,
242 };
243 status = mmagic_controller_wlan_connect(controller, &connect_args);
244 if (status != MMAGIC_STATUS_OK)
245 {
246 printf("Error %d after sending the connect command\n", status);
247 return false;
248 }
249
250 struct mmagic_core_ip_status_rsp_args ip_status_rsp_args = {};
251 uint32_t timeout = mmosal_get_time_ms() + LINK_STATE_TIMEOUT_MS;
252 while (mmosal_time_lt(mmosal_get_time_ms(), timeout))
253 {
254 status = mmagic_controller_ip_status(controller, &ip_status_rsp_args);
255 if ((status == MMAGIC_STATUS_OK) &&
256 (ip_status_rsp_args.status.link_state == MMAGIC_IP_LINK_STATE_UP))
257 {
258 printf("Link Up\n");
259 printf("Link is up %s. Time: %lu ms, ",
260 ip_status_rsp_args.status.dhcp_enabled ? "(DHCP)" : "(Static)",
262 printf("IP: %s, ", ip_status_rsp_args.status.ip_addr.addr);
263 printf("Netmask: %s, ", ip_status_rsp_args.status.netmask.addr);
264 printf("Gateway: %s", ip_status_rsp_args.status.gateway.addr);
265 printf("\n");
266 return true;
267 }
269 }
270
271 return false;
272}
273
282static bool is_wlan_connected(struct mmagic_controller *controller)
283{
285 printf("\n\n#### Example check WLAN connection using MMAGIC Controller ####\n\n");
287
288 printf("Checking SSID and password match expected values\n");
289 struct string32 agent_ssid = {};
290 const size_t ssid_len = sizeof(STRINGIFY(SSID)) - 1;
291 status = mmagic_controller_get_wlan_ssid(controller, &agent_ssid);
292 if (status != MMAGIC_STATUS_OK)
293 {
294 printf("Error %d getting the wlan ssid\n", status);
295 return false;
296 }
297 if ((ssid_len != agent_ssid.len) || memcmp(agent_ssid.data, STRINGIFY(SSID), ssid_len + 1))
298 {
299 printf("SSID mismatch\n");
300 return false;
301 }
302
303 struct string100 agent_pwd = {};
304 const size_t pwd_len = sizeof(STRINGIFY(SAE_PASSPHRASE)) - 1;
305 status = mmagic_controller_get_wlan_password(controller, &agent_pwd);
306 if (status != MMAGIC_STATUS_OK)
307 {
308 printf("Error %d getting the wlan password\n", status);
309 return false;
310 }
311 if ((pwd_len != agent_pwd.len) || memcmp(agent_pwd.data, STRINGIFY(SAE_PASSPHRASE),
312 pwd_len + 1))
313 {
314 printf("Password mismatch\n");
315 return false;
316 }
317
318 printf("Checking STA connection status\n");
319 struct mmagic_core_wlan_get_sta_status_rsp_args rsp_args = {};
320 status = mmagic_controller_wlan_get_sta_status(controller, &rsp_args);
321 if (status != MMAGIC_STATUS_OK)
322 {
323 printf("Error %d getting wlan sta status\n", status);
324 return false;
325 }
327 {
328 printf("STA not connected\n");
329 return false;
330 }
331
332 printf("Checking link status\n");
333 struct mmagic_core_ip_status_rsp_args ip_status_rsp_args = {};
334 for (int attempts = 2; attempts > 0; --attempts)
335 {
336 status = mmagic_controller_ip_status(controller, &ip_status_rsp_args);
337 if ((status == MMAGIC_STATUS_OK) &&
338 (ip_status_rsp_args.status.link_state == MMAGIC_IP_LINK_STATE_UP))
339 {
340 printf("Link is up %s. Time: %lu ms, ",
341 ip_status_rsp_args.status.dhcp_enabled ? "(DHCP)" : "(Static)",
343 printf("IP: %s, ", ip_status_rsp_args.status.ip_addr.addr);
344 printf("Netmask: %s, ", ip_status_rsp_args.status.netmask.addr);
345 printf("Gateway: %s", ip_status_rsp_args.status.gateway.addr);
346 printf("\n");
347 return true;
348 }
350 }
351
352 printf("Link Down\n");
353 return false;
354}
355
360{
362 struct mmagic_controller *controller;
364 uint8_t stream_id;
365};
366
374 const struct mmagic_wlan_beacon_rx_event_args *args, void *arg)
375{
376 uint32_t offset = 0;
377
378 MM_UNUSED(arg);
379
380 while (offset < args->vendor_ies.len)
381 {
382 uint8_t ie_type;
383 uint8_t ie_len;
384 uint32_t ii;
385
386 if (offset + 2 > args->vendor_ies.len)
387 {
388 printf("Beacon IEs malformed!\n");
389 break;
390 }
391
392 ie_type = args->vendor_ies.data[offset];
393 ie_len = args->vendor_ies.data[offset + 1];
394
395 offset += 2;
396
397 if (offset + ie_len > args->vendor_ies.len)
398 {
399 printf("Beacon IEs malformed!\n");
400 break;
401 }
402
403 printf(" IE type 0x%02x, IE len 0x%02x, Contents: ", ie_type, ie_len);
404 for (ii = 0; ii < ie_len; ii++)
405 {
406 printf("%02x", args->vendor_ies.data[offset++]);
407 }
408 printf("\n");
409 }
410}
411
419static void beacon_monitor_example_start(struct mmagic_controller *controller)
420{
421 enum mmagic_status status;
422
423 printf("\n\n#### Example Beacon Monitor using MMAGIC Controller ####\n\n");
424
425 struct mmagic_core_wlan_beacon_monitor_enable_cmd_args beacon_monitor_args = {
426 /* OUI for default Microsoft WMN/WME IE */
427 .oui_filter = {.count = 1, .ouis = { { { 0x00, 0x50, 0xF2 } } }}
428 };
429
431
432 status = mmagic_controller_wlan_beacon_monitor_enable(controller, &beacon_monitor_args);
433 if (status != MMAGIC_STATUS_OK)
434 {
435 printf("Error %d enabling beacon monitor\n", status);
436 return;
437 }
438 printf("Enabled beacon monitor for OUI %02x:%02x:%02x\n",
439 beacon_monitor_args.oui_filter.ouis[0].oui[0],
440 beacon_monitor_args.oui_filter.ouis[0].oui[1],
441 beacon_monitor_args.oui_filter.ouis[0].oui[2]);
442}
443
451static void tcp_client_example(struct mmagic_controller *controller)
452{
453 printf("\n\n#### Example TCP Client using MMAGIC Controller ####\n\n");
454 enum mmagic_status status;
455
456 struct mmagic_core_tcp_connect_cmd_args tcp_connect_args = {
457 .url = {.data = "google.com", .len = strlen("google.com")},
458 .port = 80
459 };
460 struct mmagic_core_tcp_connect_rsp_args tcp_rsp_args = {};
461 status = mmagic_controller_tcp_connect(controller, &tcp_connect_args, &tcp_rsp_args);
462 if (status != MMAGIC_STATUS_OK)
463 {
464 printf("Error %d establishing TCP connection\n", status);
465 MMOSAL_ASSERT(false);
466 }
467 uint8_t tcp_stream_id = tcp_rsp_args.stream_id;
468 printf("Opened TCP socket on stream_id %u\n", tcp_stream_id);
469
470 struct mmagic_core_tcp_send_cmd_args tcp_send_cmd_args = {
471 .stream_id = tcp_stream_id,
472 .buffer = {.data = "GET /\n", .len = strlen("GET /\n")}
473 };
474 status = mmagic_controller_tcp_send(controller, &tcp_send_cmd_args);
475 if (status != MMAGIC_STATUS_OK)
476 {
477 printf("Error %d whilst sending data\n", status);
478 MMOSAL_ASSERT(false);
479 }
480 printf("Successfully sent GET request\n");
481
482 struct mmagic_core_tcp_recv_cmd_args tcp_recv_cmd_args = {
483 .stream_id = tcp_stream_id,
484 .len = 1536,
485 .timeout = 5000,
486 };
487 struct mmagic_core_tcp_recv_rsp_args tcp_recv_rsp_args = {};
488 status = mmagic_controller_tcp_recv(controller, &tcp_recv_cmd_args, &tcp_recv_rsp_args);
489 if (status != MMAGIC_STATUS_OK)
490 {
491 printf("Error %d whilst receiving data\n", status);
492 }
493 else
494 {
495 printf("Received: %.12s, Length %u\n", tcp_recv_rsp_args.buffer.data,
496 tcp_recv_rsp_args.buffer.len);
497 }
498
499 struct mmagic_core_tcp_close_cmd_args tcp_close_cmd_args = {.stream_id = tcp_stream_id};
500 status = mmagic_controller_tcp_close(controller, &tcp_close_cmd_args);
501 if (status != MMAGIC_STATUS_OK)
502 {
503 printf("Error %d whilst closing tcp socket\n", status);
504 MMOSAL_ASSERT(false);
505 }
506 printf("Closed TCP Socket\n");
507}
508
513{
515 struct mmagic_controller *controller;
517 uint8_t stream_id;
518};
519
525static void tcp_echo_server_task(void *args)
526{
527 enum mmagic_status status;
528 struct tcp_echo_server_thread_args *thread_args =
529 (struct tcp_echo_server_thread_args *)args;
530 struct mmagic_controller *controller = thread_args->controller;
531 uint8_t stream_id = thread_args->stream_id;
532
533 printf("Accepted a TCP connection on stream_id %u\n", stream_id);
534
535 struct mmagic_core_tcp_recv_cmd_args tcp_recv_cmd_args = {
537 .len = 1536,
538 .timeout = 1000,
539 };
540 struct mmagic_core_tcp_recv_rsp_args tcp_recv_rsp_args = {};
541 struct mmagic_core_tcp_send_cmd_args tcp_send_cmd_args =
542 {
544 };
545
546 while (true)
547 {
548 status = mmagic_controller_tcp_recv(controller, &tcp_recv_cmd_args, &tcp_recv_rsp_args);
549 if (status == MMAGIC_STATUS_TIMEOUT)
550 {
551 continue;
552 }
553 else if (status == MMAGIC_STATUS_CLOSED)
554 {
555 printf("Connection closed by the other side!\n");
556 break;
557 }
558 else if (status != MMAGIC_STATUS_OK)
559 {
560 printf("Error %d whilst receiving data\n", status);
561 break;
562 }
563 printf("Received: %d bytes, echoing.\n", tcp_recv_rsp_args.buffer.len);
564
565 memcpy(tcp_send_cmd_args.buffer.data, tcp_recv_rsp_args.buffer.data,
566 tcp_recv_rsp_args.buffer.len);
567 tcp_send_cmd_args.buffer.len = tcp_recv_rsp_args.buffer.len;
568 status = mmagic_controller_tcp_send(controller, &tcp_send_cmd_args);
569 if (status != MMAGIC_STATUS_OK)
570 {
571 printf("Error %d whilst sending data\n", status);
572 break;
573 }
574 }
575
576 struct mmagic_core_tcp_close_cmd_args tcp_close_cmd_args =
577 {
579 };
580 status = mmagic_controller_tcp_close(controller, &tcp_close_cmd_args);
581 if (status != MMAGIC_STATUS_OK)
582 {
583 printf("Error %u whilst trying to close the TCP socket on stream_id %u\n",
584 status, stream_id);
585 }
586 printf("Closed TCP socket\n");
587}
588
598static enum mmagic_status tcp_echo_server_start(struct mmagic_controller *controller, uint16_t port)
599{
600 printf("\n\n#### Example TCP Echo Server using MMAGIC Controller ####\n\n");
601 enum mmagic_status status;
602 static struct tcp_echo_server_thread_args thread_args;
603
604 struct mmagic_core_tcp_bind_cmd_args tcp_bind_cmd_args = {.port = port};
605 struct mmagic_core_tcp_bind_rsp_args tcp_bind_rsp_args = {};
606 status = mmagic_controller_tcp_bind(controller, &tcp_bind_cmd_args, &tcp_bind_rsp_args);
607 if (status != MMAGIC_STATUS_OK)
608 {
609 printf("Error %u whilst opening the tcp socket\n", status);
610 return status;
611 }
612 uint8_t tcp_socket_stream_id = tcp_bind_rsp_args.stream_id;
613 printf("Opened listening socket (Port %u) on stream_id %u\n",
614 tcp_bind_cmd_args.port, tcp_socket_stream_id);
615
616 struct mmagic_core_tcp_accept_cmd_args tcp_accept_cmd_args = {
617 .stream_id = tcp_socket_stream_id
618 };
619 struct mmagic_core_tcp_accept_rsp_args tcp_accept_rsp_args = {};
620 while (true)
621 {
622 status = mmagic_controller_tcp_accept(controller,
623 &tcp_accept_cmd_args,
624 &tcp_accept_rsp_args);
625 if (status != MMAGIC_STATUS_OK)
626 {
627 printf("Error %u whilst trying to accept a TCP connection\n", status);
628 break;
629 }
630
631 thread_args.stream_id = tcp_accept_rsp_args.stream_id;
632 thread_args.controller = controller;
633
635 MMOSAL_TASK_PRI_LOW, 2048, "tcp_echo_server_task");
636 }
637
638 struct mmagic_core_tcp_close_cmd_args tcp_close_cmd_args =
639 {
640 .stream_id = tcp_socket_stream_id
641 };
642 status = mmagic_controller_tcp_close(controller, &tcp_close_cmd_args);
643 if (status != MMAGIC_STATUS_OK)
644 {
645 printf("Error %u whilst trying to close the listening socket on stream_id %u\n",
646 status, tcp_socket_stream_id);
647 }
648 else
649 {
650 printf("Closed listening socket\n");
651 }
652 return status;
653}
654
660static void run_examples_task(void *args)
661{
662 MM_UNUSED(args);
663
664 agent_started_semb = mmosal_semb_create("agent_started");
667 init_args.agent_start_arg = (void *)agent_started_semb;
668
669 struct mmagic_controller *controller = mmagic_controller_init(&init_args);
670
671 enum {
672 AGENT_ACTION_TIMEOUT_MS = 1000,
673 };
674
675 bool agent_already_running = false;
676 enum mmagic_status status;
677 printf("M2M Controller enabled. Awaiting Agent start\n");
678 if (mmosal_semb_wait(agent_started_semb, AGENT_ACTION_TIMEOUT_MS))
679 {
680 goto agent_started;
681 }
682
683 printf("No agent start notification, agent may already be running.\n");
684 printf("Attempting sync to recover connection.\n");
685 status = mmagic_controller_agent_sync(controller, AGENT_ACTION_TIMEOUT_MS);
686 if (status == MMAGIC_STATUS_OK)
687 {
688 agent_already_running = true;
689 /* Check for existing connection */
690 if (is_wlan_connected(controller))
691 {
692 printf("WLAN connection reattached\n");
693 goto agent_connected;
694 }
695 goto agent_started;
696 }
697
698 printf("Sync failed with status %d, attempting LLC agent reset.\n", status);
700 if (mmosal_semb_wait(agent_started_semb, AGENT_ACTION_TIMEOUT_MS))
701 {
702 goto agent_started;
703 }
704
705 printf("LLC reset failed. Please hard reset the agent.\n");
707
708agent_started:
709 if (!wlan_connect(controller))
710 {
711 printf("Failed to connect\n");
712 return;
713 }
714 printf("WLAN connection established\n");
715
716agent_connected:
718
719 tcp_client_example(controller);
720
721 status = tcp_echo_server_start(controller, TCP_ECHCO_SERVER_PORT);
722 if ((status == MMAGIC_STATUS_SOCKET_LISTEN_FAILED) && agent_already_running)
723 {
724 /* Socket may already be open from previous run, try another port */
725 status = tcp_echo_server_start(controller, TCP_ECHCO_SERVER_PORT + mmhal_random_u32(1, 10));
726 printf("TCP echo server ended with status %d\n", status);
727 }
728}
729
734void app_init(void)
735{
736 printf("\n\nM2M Controller Example (Built " __DATE__ " " __TIME__ ")\n\n");
737
738 /* Keep controller awake for now */
740
741 /* Run the examples in a different task to cater for the higher stack size requirements */
743 MMOSAL_TASK_PRI_LOW, 2048, "run_examples_task");
744}
mmagic_status
Enumeration of return status codes.
@ MMAGIC_IP_LINK_STATE_UP
Link is up.
@ MMAGIC_STA_STATE_CONNECTED
Connected to the AP.
@ MMAGIC_STATUS_OK
Operation was successful.
@ MMAGIC_STATUS_SOCKET_LISTEN_FAILED
Socket listen failed.
@ MMAGIC_STATUS_TIMEOUT
The operation timed out.
@ MMAGIC_STATUS_CLOSED
Failed due to stream being closed from the other side.
struct mmagic_controller * mmagic_controller_init(const struct mmagic_controller_init_args *args)
Initialize the Controller.
#define MMAGIC_CONTROLLER_ARGS_INIT
Initializer for mmagic_controller_init_args.
enum mmagic_status mmagic_controller_agent_sync(struct mmagic_controller *controller, uint32_t timeout_ms)
Sends a sync request to the agent and waits for a sync response.
enum mmagic_status mmagic_controller_request_agent_reset(struct mmagic_controller *controller)
Sends a reset request to the agent.
static enum mmagic_status mmagic_controller_ip_status(struct mmagic_controller *controller, struct mmagic_core_ip_status_rsp_args *rsp_args)
Gets the status of the IP stack.
static enum mmagic_status mmagic_controller_tcp_connect(struct mmagic_controller *controller, struct mmagic_core_tcp_connect_cmd_args *cmd_args, struct mmagic_core_tcp_connect_rsp_args *rsp_args)
Opens a client TCP socket and returns its stream ID.
static enum mmagic_status mmagic_controller_tcp_accept(struct mmagic_controller *controller, struct mmagic_core_tcp_accept_cmd_args *cmd_args, struct mmagic_core_tcp_accept_rsp_args *rsp_args)
Waits for an incoming socket connection and returns a new stream ID.
static enum mmagic_status mmagic_controller_tcp_recv(struct mmagic_controller *controller, struct mmagic_core_tcp_recv_cmd_args *cmd_args, struct mmagic_core_tcp_recv_rsp_args *rsp_args)
Reads from a socket.
static enum mmagic_status mmagic_controller_tcp_bind(struct mmagic_controller *controller, struct mmagic_core_tcp_bind_cmd_args *cmd_args, struct mmagic_core_tcp_bind_rsp_args *rsp_args)
Opens a server TCP socket and returns its stream ID.
static enum mmagic_status mmagic_controller_tcp_send(struct mmagic_controller *controller, struct mmagic_core_tcp_send_cmd_args *cmd_args)
Writes to a socket.
static enum mmagic_status mmagic_controller_tcp_close(struct mmagic_controller *controller, struct mmagic_core_tcp_close_cmd_args *cmd_args)
Closes and frees the socket.
static enum mmagic_status mmagic_controller_set_wlan_ssid(struct mmagic_controller *controller, const char *var)
Sets ssid setting for module wlan.
static enum mmagic_status mmagic_controller_set_wlan_password(struct mmagic_controller *controller, const char *var)
Sets password setting for module wlan.
static enum mmagic_status mmagic_controller_get_wlan_ssid(struct mmagic_controller *controller, struct string32 *var)
Gets ssid setting for module wlan.
static enum mmagic_status mmagic_controller_get_wlan_password(struct mmagic_controller *controller, struct string100 *var)
Gets password setting for module wlan.
static enum mmagic_status mmagic_controller_wlan_beacon_monitor_enable(struct mmagic_controller *controller, struct mmagic_core_wlan_beacon_monitor_enable_cmd_args *cmd_args)
Enable beacon monitoring with the given filter settings.
static enum mmagic_status mmagic_controller_wlan_get_sta_status(struct mmagic_controller *controller, struct mmagic_core_wlan_get_sta_status_rsp_args *rsp_args)
Retrieves the STA status of the WLAN interface.
void mmagic_controller_register_wlan_beacon_rx_handler(struct mmagic_controller *controller, mmagic_wlan_beacon_rx_event_handler_t handler, void *arg)
Register a handler for the wlan-beacon_rx event.
static enum mmagic_status mmagic_controller_wlan_connect(struct mmagic_controller *controller, struct mmagic_core_wlan_connect_cmd_args *cmd_args)
Brings up the WLAN interface and connects to the AP with configured parameters.
void mmhal_set_deep_sleep_veto(uint8_t veto_id)
Sets a deep sleep veto that will prevent the device from entering deep sleep.
uint32_t mmhal_random_u32(uint32_t min, uint32_t max)
Generate a random 32 bit integer within the given range.
@ MMHAL_VETO_ID_APP_MIN
Start of deep sleep veto ID range that is available for application use.
Definition: mmhal.h:300
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:927
bool mmosal_semb_wait(struct mmosal_semb *semb, uint32_t timeout_ms)
Wait for a counting semaphore.
struct mmosal_semb * mmosal_semb_create(const char *name)
Create a new binary semaphore.
bool mmosal_semb_give(struct mmosal_semb *semb)
Give a binary semaphore.
struct mmosal_task * mmosal_task_create(mmosal_task_fn_t task_fn, void *argument, enum mmosal_task_priority priority, unsigned stack_size_u32, const char *name)
Create a new task.
void mmosal_task_sleep(uint32_t duration_ms)
Sleep for a period of time, yielding during that time.
@ MMOSAL_TASK_PRI_LOW
Low priority.
Definition: mmosal.h:183
uint32_t mmosal_get_time_ms(void)
Get the system time in milliseconds.
static bool mmosal_time_lt(uint32_t a, uint32_t b)
Check if time a is less than time b, taking into account wrapping.
Definition: mmosal.h:662
#define MM_UNUSED(_x)
Casts the given expression to void to avoid "unused" warnings from the compiler.
Definition: mmutils.h:69
static void tcp_echo_server_task(void *args)
This task handles a single incoming TCP connection.
static void run_examples_task(void *args)
Runs the examples.
static struct mmosal_semb * agent_started_semb
Binary semaphore used to indicate when an agent start notification has been received.
static bool wlan_connect(struct mmagic_controller *controller)
This function illustrates how to establish a wlan connection using the mmagic_controller interface.
#define TCP_ECHCO_SERVER_PORT
Port the the TCP echo server will bind to.
void beacon_monitor_rx_handler(const struct mmagic_wlan_beacon_rx_event_args *args, void *arg)
Handler for the beacon monitor event handler callback.
static enum mmagic_status tcp_echo_server_start(struct mmagic_controller *controller, uint16_t port)
This function illustrates how to start a TCP server and listen for a connection.
#define STRINGIFY(x)
Convert the content of the given macro to a string.
#define SAE_PASSPHRASE
Passphrase of the AP (ignored if security type is not SAE).
static bool is_wlan_connected(struct mmagic_controller *controller)
This function illustrates how to check if the agent already has an active connection.
#define LINK_STATE_TIMEOUT_MS
Duration to wait for the link to be established after WLAN reports connected.
#define SSID
SSID of the AP to connect to.
static void tcp_client_example(struct mmagic_controller *controller)
This function illustrates how to open a tcp client, send and receive some data and close the connecti...
void app_init(void)
Main entry point to the application.
void agent_start_handler(struct mmagic_controller *controller, void *arg)
Handler for the "Agent start" callback.
static void beacon_monitor_example_start(struct mmagic_controller *controller)
This function illustrates how to subscribe to and receive custom vendor IEs from beacons.
Arguments for beacon monitor task.
uint8_t stream_id
The stream ID.
struct mmagic_controller * controller
The controller reference.
Initialization structure for mmagic_controller.
mmagic_controller_agent_start_cb_t agent_start_cb
Callback function to executed any time a event that the agent has started is received.
void * agent_start_arg
User argument that will be passed when the agent_start_cb is executed.
Response arguments structure for ip_status.
struct struct_ip_status status
Reference to the struct to return the IP status retrieved from the network stack.
Command arguments structure for tcp_accept.
uint8_t stream_id
Stream ID of the bound socket.
Response arguments structure for tcp_accept.
uint8_t stream_id
Stream ID of the new incoming connection.
Command arguments structure for tcp_bind.
uint16_t port
TCP port to listen on.
Response arguments structure for tcp_bind.
uint8_t stream_id
Stream ID of the opened socket.
Command arguments structure for tcp_close.
uint8_t stream_id
Stream ID of the socket to close.
Command arguments structure for tcp_connect.
struct string254 url
URL of the server to connect to.
Response arguments structure for tcp_connect.
uint8_t stream_id
Stream ID of the opened socket.
Command arguments structure for tcp_recv.
uint8_t stream_id
Stream ID of the socket to receive from.
Response arguments structure for tcp_recv.
struct raw1536 buffer
Buffer of read data.
Command arguments structure for tcp_send.
struct raw1536 buffer
Buffer to send.
uint8_t stream_id
Stream ID of the socket to send on.
Command arguments structure for wlan_beacon_monitor_enable.
struct struct_oui_list oui_filter
OUIs to monitor.
Command arguments structure for wlan_connect.
uint32_t timeout
Duration in milliseconds to wait for connection establish, if connection does not get established an ...
Response arguments structure for wlan_get_sta_status.
enum mmagic_sta_state sta_status
The current STA status.
Event arguments structure for wlan_beacon_rx.
struct raw1536 vendor_ies
Raw octet string of Vendor Information Elements contained in the beacon.
uint8_t data[1536]
The acutal data buffer.
uint16_t len
Length of data.
String type with maximum length of 100 (excluding null terminator).
uint8_t len
Length of string contents (excluding null terminator).
char data[100+1]
The string contents.
char data[254+1]
The string contents.
String type with maximum length of 32 (excluding null terminator).
uint8_t len
Length of string contents (excluding null terminator).
char data[32+1]
The string contents.
char addr[48]
Array containing the IP string.
struct struct_ip_addr netmask
Current IP network mask.
struct struct_ip_addr ip_addr
Current IP address.
bool dhcp_enabled
Whether or not dhcp is enabled.
enum mmagic_ip_link_state link_state
Current link state.
struct struct_ip_addr gateway
Current IP gateway.
struct struct_oui ouis[5]
The OUI data.
uint8_t count
The number of OUIs in the list.
uint8_t oui[3]
The 3 octet OUI.
Arguments for TCP echo server task.
uint8_t stream_id
The stream ID.
struct mmagic_controller * controller
The controller reference.