RDK Documentation (Open Sourced RDK Components)
switch_interfaces.c
1 #include "wifi_common_hal.h"
2 #include "wifi_client_hal.h"
3 
4 #include <stdarg.h>
5 #include <string.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdbool.h>
10 #include <unistd.h>
11 
12 static void wifi_neightListFree(wifi_neighbor_ap_t * bss)
13 {
14  if (bss)
15  free(bss);
16 }
17 
18 static void wifi_assert(int wifi_status, const char *format, ...)
19  __attribute__((format(printf, 2, 3)));
20 
21 #define NWLAN_IFACES 2
22 
23 static char *wlan_iface_list[NWLAN_IFACES] = {
24  "wlx984827474ec9",
25  "wlan1"
26 };
27 
28 int main()
29 {
30  int iface_idx = 0;
31  uint32_t bss_count = 0;
32  wifi_neighbor_ap_t *bss_list = NULL;
33 
34  while (true) {
35  int wifi_status = 0;
36 
37  wifi_halConfig_t conf;
38  strcpy(conf.wlan_Interface, wlan_iface_list[iface_idx++]);
39  if (iface_idx == NWLAN_IFACES)
40  iface_idx = 0;
41 
42  wifi_status = wifi_initWithConfig(&conf);
43  wifi_assert(wifi_status, "wifi_initWithSettings:%s", conf.wlan_Interface);
44 
45  wifi_status = wifi_getNeighboringWiFiDiagnosticResult(0, &bss_list, &bss_count);
46  wifi_assert(wifi_status, "wifi_getNeighboringWiFiDiagnosticResult");
47 
48  wifi_neightListFree(bss_list);
49  wifi_status = wifi_uninit();
50  wifi_assert(wifi_status, "wifi_uninit");
51 
52  sleep(3);
53  }
54 
55  return 0;
56 }
57 
58 void wifi_assert(int wifi_status, const char *format, ...)
59 {
60  if (wifi_status != 0) {
61  va_list arg_list;
62  va_start(arg_list, format);
63  vfprintf(stderr, format, arg_list);
64  va_end(arg_list);
65  fprintf(stderr, "\twifi_status:%d\n", wifi_status);
66  abort();
67  }
68 }
_wifi_halSettings
Definition: wifi_common_hal.h:559
_wifi_neighbor_ap
Definition: wifi_common_hal.h:409
wifi_uninit
int wifi_uninit()
Uninitilizes wifi module.
Definition: wifi_common_hal.c:482
wifi_getNeighboringWiFiDiagnosticResult
int wifi_getNeighboringWiFiDiagnosticResult(int radioIndex, wifi_neighbor_ap_t **neighbor_ap_array, unsigned int *output_array_size)
Get neighbor wifi diagnostics.