3 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
30 extern wifi_mesh_h mesh;
32 static char gate_announce[MENU_DATA_SIZE + 1] = "1";
33 static char hwmp_root_mode[MENU_DATA_SIZE + 1] = "4";
34 static char stp[MENU_DATA_SIZE + 1] = "1";
36 static char ssid[MENU_DATA_SIZE + 1] = "meshnet";
37 static char passphrase[MENU_DATA_SIZE + 1] = "11223344";
38 static char mode[MENU_DATA_SIZE + 1] = "ac";
39 static char softap_channel[MENU_DATA_SIZE + 1] = "36";
40 static char visibility[MENU_DATA_SIZE + 1] = "1";
41 static char max_stations[MENU_DATA_SIZE + 1] = "10";
42 static char security[MENU_DATA_SIZE + 1] = "2";
44 static char meshid[MENU_DATA_SIZE + 1] = "meshnet";
45 static char mesh_channel[MENU_DATA_SIZE + 1] = "161";
46 static char mesh_security[MENU_DATA_SIZE + 1] = "0";
47 static char mesh_passphrase[MENU_DATA_SIZE + 1] = "";
49 static char network_idx[MENU_DATA_SIZE + 1] = "1";
51 /* Found Mesh Network */
52 static int g_scan_net_idx = 0;
53 GList *g_found_network_list = NULL;
57 static void found_mesh_network_cb(wifi_mesh_network_h network, void* user_data)
60 wifi_mesh_network_h net = NULL;
65 wifi_mesh_security_type_e security;
68 ret = wifi_mesh_network_clone(&net, network);
69 if (WIFI_MESH_ERROR_NONE != ret) {
70 msgr("Failed to clone found network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
74 g_found_network_list = g_list_append(g_found_network_list, net);
76 wifi_mesh_network_get_meshid(net, &meshid);
77 wifi_mesh_network_get_bssid(net, &bssid);
78 wifi_mesh_network_get_channel(net, &channel);
79 wifi_mesh_network_get_rssi(net, &rssi);
80 wifi_mesh_network_get_data_rate(net, &data_rate);
81 wifi_mesh_network_get_security(net, &security);
82 msgb(" [%02d] Mesh ID[%-10s] BSSID[%s] Channel[%d] RSSI[%ddBm] Date Rate[%dMbps] Security[%4s]",
83 g_scan_net_idx, meshid, bssid, channel, rssi == 0 ? 0 : rssi-120, data_rate,
84 (MESH_SECURITY_SAE == security) ? "SAE" : "NONE");
88 if (meshid) free(meshid);
89 if (bssid) free(bssid);
92 static void connected_peer_cb(wifi_mesh_peer_h peer, void* user_data)
96 wifi_mesh_peer_get_address(peer, &address);
97 msgb(" Peer Address [%s]", address);
103 static void found_station_cb(wifi_mesh_station_info_h station, void* user_data)
105 int ret = WIFI_MESH_ERROR_NONE;
106 gchar *bssid = NULL; /* station bssid ex) 7c:dd:90:62:37:cf (on mesh0) */
107 guint inactive_time; /**< inactive time ex) 1685 ms */
108 guint64 rx_bytes; /**< rx bytes ex) 34174 */
109 guint rx_packets; /**< rx packet ex) 1181 */
110 guint64 tx_bytes; /**< tx bytes ex) 6877 */
111 guint tx_packets; /**< tx packets ex) 76 */
112 guint tx_retries; /**< tx retries ex) 0 */
113 guint tx_failed; /**< tx failed ex) 0 */
114 guint beacon_loss; /**< beacon loss count ex) 0 */
115 guint64 beacon_rx; /**< beacon rx ex) 0 */
116 guint64 rx_drop_misc; /**< rx drop misc ex) 0 */
117 gint signal; /**< Signal ex) -64 dBm */
118 gint signal_avg; /**< Average Signal ex) -63 dBm */
119 guint tx_bitrate; /**< tx bitrate ex) 54.0 MBit/s => 540 */
120 guint rx_bitrate; /**< rx bitrate ex) 5.5 MBit/s => 55 */
121 gushort mesh_llid; /**< mesh_llid ex) 51731 */
122 gushort mesh_plid; /**< mesh plid ex) 35432 */
123 guchar mesh_plink; /**< mesh plink ex) ESTAB */
124 guint local_ps_mode; /**< mesh local power save mode ex) ACTIVE */
125 guint peer_ps_mode; /**< mesh peer power save mode ex) ACTIVE */
126 guint non_peer_ps_mode; /**< mesh non-peer power save mode ex) ACTIVE */
127 gboolean authorized; /**< authorized ex) yes */
128 gboolean authenticated; /**< authenticated ex) yes */
129 gboolean associated; /**< associated ex) yes */
130 gboolean preamble; /**< preamble ex) long */
131 gboolean wmm_wme; /**< WMM/WME supported ex) yes */
132 gboolean mfp; /**< MFP ex) no */
133 gboolean tdls_peer; /**< TDLS peer ex) no */
134 guchar dtim_period; /**< DTIM period ex) 0 */
135 gushort beacon_interval; /**< beacon interval ex) 1000 */
136 gboolean cts_protection; /**< CTS protection */
137 gboolean short_preamble; /**< short preamble */
138 gboolean short_slot_time; /**< short slot time supported ex) yes */
139 guint connected_time; /**< connected time : ex) 256 seconds */
141 msgp("[%d] Station Information Received", g_idx++);
146 ret = wifi_mesh_get_sta_bssid(station, &bssid);
147 if (WIFI_MESH_ERROR_NONE == ret)
148 msg("bssid = %s", bssid);
149 ret = wifi_mesh_get_sta_inactive_time(station, &inactive_time);
150 if (WIFI_MESH_ERROR_NONE == ret)
151 msg("inactive_time = %d", inactive_time);
152 ret = wifi_mesh_get_sta_rx_bytes(station, &rx_bytes);
153 if (WIFI_MESH_ERROR_NONE == ret)
154 msg("rx_bytes = %"G_GUINT64_FORMAT, rx_bytes);
155 ret = wifi_mesh_get_sta_rx_packets(station, &rx_packets);
156 if (WIFI_MESH_ERROR_NONE == ret)
157 msg("rx_packets = %d", rx_packets);
158 ret = wifi_mesh_get_sta_tx_bytes(station, &tx_bytes);
159 if (WIFI_MESH_ERROR_NONE == ret)
160 msg("tx_bytes = %"G_GUINT64_FORMAT, tx_bytes);
161 ret = wifi_mesh_get_sta_tx_packets(station, &tx_packets);
162 if (WIFI_MESH_ERROR_NONE == ret)
163 msg("tx_packets = %d", tx_packets);
164 ret = wifi_mesh_get_sta_tx_retries(station, &tx_retries);
165 if (WIFI_MESH_ERROR_NONE == ret)
166 msg("tx_retries = %d", tx_retries);
167 ret = wifi_mesh_get_sta_tx_failed(station, &tx_failed);
168 if (WIFI_MESH_ERROR_NONE == ret)
169 msg("tx_failed = %d", tx_failed);
170 ret = wifi_mesh_get_sta_beacon_loss(station, &beacon_loss);
171 if (WIFI_MESH_ERROR_NONE == ret)
172 msg("beacon_loss = %d", beacon_loss);
173 ret = wifi_mesh_get_sta_beacon_rx(station, &beacon_rx);
174 if (WIFI_MESH_ERROR_NONE == ret)
175 msg("beacon_rx = %"G_GUINT64_FORMAT, beacon_rx);
176 ret = wifi_mesh_get_sta_rx_drop_misc(station, &rx_drop_misc);
177 if (WIFI_MESH_ERROR_NONE == ret)
178 msg("rx_drop_misc = %"G_GUINT64_FORMAT, rx_drop_misc);
179 ret = wifi_mesh_get_sta_signal(station, &signal);
180 if (WIFI_MESH_ERROR_NONE == ret)
181 msg("signal = %d", signal);
182 ret = wifi_mesh_get_sta_signal_avg(station, &signal_avg);
183 if (WIFI_MESH_ERROR_NONE == ret)
184 msg("signal_avg = %d", signal_avg);
185 ret = wifi_mesh_get_sta_tx_bitrate(station, &tx_bitrate);
186 if (WIFI_MESH_ERROR_NONE == ret)
187 msg("inactive_time = %d", inactive_time);
188 ret = wifi_mesh_get_sta_rx_bitrate(station, &rx_bitrate);
189 if (WIFI_MESH_ERROR_NONE == ret)
190 msg("tx_bitrate = %d", tx_bitrate);
191 ret = wifi_mesh_get_sta_mesh_llid(station, &mesh_llid);
192 if (WIFI_MESH_ERROR_NONE == ret)
193 msg("mesh_llid = %d", mesh_llid);
194 ret = wifi_mesh_get_sta_mesh_plid(station, &mesh_plid);
195 if (WIFI_MESH_ERROR_NONE == ret)
196 msg("mesh_plid = %d", mesh_plid);
197 ret = wifi_mesh_get_sta_mesh_plink(station, &mesh_plink);
198 if (WIFI_MESH_ERROR_NONE == ret)
199 msg("inactive_time = %d", inactive_time);
200 ret = wifi_mesh_get_sta_local_ps_mode(station, &local_ps_mode);
201 if (WIFI_MESH_ERROR_NONE == ret)
202 msg("inactive_time = %d", inactive_time);
203 ret = wifi_mesh_get_sta_peer_ps_mode(station, &peer_ps_mode);
204 if (WIFI_MESH_ERROR_NONE == ret)
205 msg("local_ps_mode = %d", local_ps_mode);
206 ret = wifi_mesh_get_sta_non_peer_ps_mode(station, &non_peer_ps_mode);
207 if (WIFI_MESH_ERROR_NONE == ret)
208 msg("local_ps_mode = %d", local_ps_mode);
209 ret = wifi_mesh_get_sta_authorized(station, &authorized);
210 if (WIFI_MESH_ERROR_NONE == ret)
211 msg("authorized = %d", authorized);
212 ret = wifi_mesh_get_sta_authenticated(station, &authenticated);
213 if (WIFI_MESH_ERROR_NONE == ret)
214 msg("authenticated = %d", authenticated);
215 ret = wifi_mesh_get_sta_associated(station, &associated);
216 if (WIFI_MESH_ERROR_NONE == ret)
217 msg("associated = %d", associated);
218 ret = wifi_mesh_get_sta_preamble(station, &preamble);
219 if (WIFI_MESH_ERROR_NONE == ret)
220 msg("preamble = %d", preamble);
221 ret = wifi_mesh_get_sta_wmm_wme(station, &wmm_wme);
222 if (WIFI_MESH_ERROR_NONE == ret)
223 msg("wmm_wme = %d", wmm_wme);
224 ret = wifi_mesh_get_sta_mfp(station, &mfp);
225 if (WIFI_MESH_ERROR_NONE == ret)
226 msg("wmm_wme = %d", wmm_wme);
227 ret = wifi_mesh_get_sta_tdls_peer(station, &tdls_peer);
228 if (WIFI_MESH_ERROR_NONE == ret)
229 msg("tdls_peer = %d", tdls_peer);
230 ret = wifi_mesh_get_sta_dtim_period(station, &dtim_period);
231 if (WIFI_MESH_ERROR_NONE == ret)
232 msg("dtim_period = %d", dtim_period);
233 ret = wifi_mesh_get_sta_beacon_interval(station, &beacon_interval);
234 if (WIFI_MESH_ERROR_NONE == ret)
235 msg("beacon_interval = %d", beacon_interval);
236 ret = wifi_mesh_get_sta_cts_protection(station, &cts_protection);
237 if (WIFI_MESH_ERROR_NONE == ret)
238 msg("cts_protection = %d", cts_protection);
239 ret = wifi_mesh_get_sta_short_preamble(station, &short_preamble);
240 if (WIFI_MESH_ERROR_NONE == ret)
241 msg("short_preamble = %d", short_preamble);
242 ret = wifi_mesh_get_sta_short_slot_time(station, &short_slot_time);
243 if (WIFI_MESH_ERROR_NONE == ret)
244 msg("short_slot_time = %d", short_slot_time);
245 ret = wifi_mesh_get_sta_connected_time(station, &connected_time);
246 if (WIFI_MESH_ERROR_NONE == ret)
247 msg("connected_time = %d", connected_time);
251 static void found_mpath_cb(wifi_mesh_mpath_info_h mpath, void* user_data)
253 int ret = WIFI_MESH_ERROR_NONE;
255 gchar *dest_addr = NULL; /**< destination address */
256 gchar *next_hop = NULL; /**< next hop address */
257 gchar *iface = NULL; /**< network interface for mesh */
258 guint sn; /**< sequence number */
259 guint metric; /**< metric */
260 guint qlen; /**< driver queue length */
261 guint exptime; /**< expire time */
262 guint discovery_timeout; /**< Discovery timeout */
263 guchar discovery_retries; /**< Discovery retries */
264 guchar flags; /**< Flags */
266 msgp("[%d] routing Information Received", g_idx++);
268 ret = wifi_mesh_get_mpath_dest_addr(mpath, &dest_addr);
269 if (WIFI_MESH_ERROR_NONE == ret)
270 msg("dest_addr = %s", dest_addr);
271 ret = wifi_mesh_get_mpath_next_hop(mpath, &next_hop);
272 if (WIFI_MESH_ERROR_NONE == ret)
273 msg("next_hop = %s", next_hop);
274 ret = wifi_mesh_get_mpath_iface(mpath, &iface);
275 if (WIFI_MESH_ERROR_NONE == ret)
276 msg("iface = %s", iface);
277 ret = wifi_mesh_get_mpath_sn(mpath, &sn);
278 if (WIFI_MESH_ERROR_NONE == ret)
280 ret = wifi_mesh_get_mpath_metric(mpath, &metric);
281 if (WIFI_MESH_ERROR_NONE == ret)
282 msg("metric = %d", metric);
283 ret = wifi_mesh_get_mpath_qlen(mpath, &qlen);
284 if (WIFI_MESH_ERROR_NONE == ret)
285 msg("qlen = %d", qlen);
286 ret = wifi_mesh_get_mpath_exptime(mpath, &exptime);
287 if (WIFI_MESH_ERROR_NONE == ret)
288 msg("exptime = %d", exptime);
289 ret = wifi_mesh_get_mpath_disc_timeout(mpath, &discovery_timeout);
290 if (WIFI_MESH_ERROR_NONE == ret)
291 msg("discovery_timeout = %d", discovery_timeout);
292 ret = wifi_mesh_get_mpath_disc_retries(mpath, &discovery_retries);
293 if (WIFI_MESH_ERROR_NONE == ret)
294 msg("discovery_retries = %d", discovery_retries);
295 ret = wifi_mesh_get_mpath_flags(mpath, &flags);
296 if (WIFI_MESH_ERROR_NONE == ret)
297 msg("flags = %d", flags);
302 static int run_show_found_network(MManager *mm, struct menu_data *menu)
304 int i = 1; /* Displays from 1 */
305 char *_meshid = NULL;
307 wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
311 if (NULL == g_found_network_list) {
312 msgp("There is not any scan result.. do scan first");
316 msg("Scan Results : ");
317 iter = g_found_network_list;
318 while (iter != NULL) {
319 wifi_mesh_network_h _net = iter->data;
320 wifi_mesh_network_get_meshid(_net, &_meshid);
321 wifi_mesh_network_get_channel(_net, &_channel);
322 wifi_mesh_network_get_security(_net, &_security);
323 msgb(" [%02d] Mesh ID[%-10s] Channel[%d] Security[%4s]", i++,
324 _meshid, _channel, (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE");
326 if (_meshid) free(_meshid);
328 iter = g_list_next(iter);
335 static int run_wifi_mesh_scan(MManager *mm, struct menu_data *menu)
340 ret = wifi_mesh_scan(mesh);
341 if (WIFI_MESH_ERROR_NONE != ret) {
342 msgr("Failed to scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
345 msg(" - wifi_mesh_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
350 static int run_get_found_mesh_network(MManager *mm, struct menu_data *menu)
353 msg("Get Found Mesh Network");
355 /* Clear previous found network list */
357 if (g_found_network_list)
358 g_list_free_full(g_found_network_list, (void *)wifi_mesh_network_destroy);
360 g_found_network_list = NULL;
362 ret = wifi_mesh_foreach_found_network(mesh, found_mesh_network_cb, NULL);
363 if (WIFI_MESH_ERROR_NONE != ret) {
364 msgr("Failed to wifi_mesh_foreach_found_network: [%s(0x%X)]",
365 wifi_mesh_error_to_string(ret), ret);
368 msg(" - wifi_mesh_foreach_found_network() ret: [0x%X] [%s]",
369 ret, wifi_mesh_error_to_string(ret));
374 static int run_wifi_mesh_specific_scan(MManager *mm, struct menu_data *menu)
379 msg("Specific scan");
381 if (strlen(mesh_channel))
382 channel = (unsigned short)strtol(mesh_channel, NULL, 10);
384 ret = wifi_mesh_specific_scan(mesh, meshid, channel);
385 if (WIFI_MESH_ERROR_NONE != ret) {
386 msgr("Failed to specific scan: [%s(0x%X)]",
387 wifi_mesh_error_to_string(ret), ret);
390 msg(" - wifi_mesh_specific_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
395 static int run_wifi_mesh_cancel_scan(MManager *mm, struct menu_data *menu)
400 ret = wifi_mesh_cancel_scan(mesh);
401 if (WIFI_MESH_ERROR_NONE != ret) {
402 msgr("Failed to cancel scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
405 msg(" - wifi_mesh_cancel_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
410 static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu)
415 ret = wifi_mesh_is_started(mesh, &is_started);
416 if (WIFI_MESH_ERROR_NONE != ret) {
417 msgr("Failed to check mesh started: [%s(0x%X)]",
418 wifi_mesh_error_to_string(ret), ret);
422 if (is_started == true) {
423 msg("Mesh is already enabled");
429 ret = wifi_mesh_start(mesh);
430 if (WIFI_MESH_ERROR_NONE != ret) {
431 msgr("Failed to enable mesh network: [%s(0x%X)]",
432 wifi_mesh_error_to_string(ret), ret);
435 msg(" - wifi_mesh_start() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
440 static int run_wifi_mesh_disable(MManager *mm, struct menu_data *menu)
445 ret = wifi_mesh_stop(mesh);
446 if (WIFI_MESH_ERROR_NONE != ret) {
447 msgr("Failed to disable mesh network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
450 msg(" - wifi_mesh_stop() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
455 static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu)
458 char *_meshid = NULL;
462 wifi_mesh_connection_state_e _state = WIFI_MESH_CONNECTION_STATE_DISCONNECTED;
463 wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
464 wifi_mesh_ip_config_type_e _ipv4_type = WIFI_MESH_IP_CONFIG_TYPE_UNKNOWN;
465 char *_ipv4_address = NULL;
466 char *_ipv4_netmask = NULL;
467 wifi_mesh_network_h network = NULL;
469 msg("Get Joined Mesh Network Information");
471 ret = wifi_mesh_is_joined(mesh, &joined);
472 if (WIFI_MESH_ERROR_NONE != ret) {
473 msgr("Failed to check network join status: [%s(0x%X)]",
474 wifi_mesh_error_to_string(ret), ret);
478 ret = wifi_mesh_get_joined_network(mesh, &network);
479 if (WIFI_MESH_ERROR_NONE != ret) {
480 msgr("Failed to get joined mesh network: [%s(0x%X)]",
481 wifi_mesh_error_to_string(ret), ret);
485 if (NULL != network) {
486 wifi_mesh_network_get_meshid(network, &_meshid);
487 msgb(" Mesh ID = %s", _meshid);
488 wifi_mesh_network_get_bssid(network, &_bssid);
489 msgb(" BSSID = %s", _bssid);
490 wifi_mesh_network_get_channel(network, &_channel);
491 msgb(" Channel = %d", _channel);
492 wifi_mesh_network_get_security(network, &_security);
493 msgb(" Security = %s",
494 (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE");
495 wifi_mesh_network_get_connection_state(network, &_state);
496 msgb(" State = %s", wifi_mesh_connection_event_to_string(_state));
497 wifi_mesh_network_get_ip_config_type(network,
498 WIFI_MESH_ADDRESS_FAMILY_IPV4, &_ipv4_type);
499 msgb(" IPv4 Config Type = %d", _ipv4_type);
500 wifi_mesh_network_get_ip_address(network, WIFI_MESH_ADDRESS_FAMILY_IPV4,
502 msgb(" IPv4 Address = %s", _ipv4_address);
503 wifi_mesh_network_get_subnet_mask(network,
504 WIFI_MESH_ADDRESS_FAMILY_IPV4, &_ipv4_netmask);
505 msgb(" IPv4 Subnet Mask = %s", _ipv4_netmask);
507 if (_meshid) free(_meshid);
508 if (_bssid) free(_bssid);
509 if (_ipv4_address) free(_ipv4_address);
510 if (_ipv4_netmask) free(_ipv4_netmask);
513 msg(" - wifi_mesh_get_joined_network() ret: [0x%X] [%s]",
514 ret, wifi_mesh_error_to_string(ret));
519 static int run_get_connected_peers(MManager *mm, struct menu_data *menu)
522 msg("Get Connected Mesh Peers");
524 ret = wifi_mesh_foreach_connected_peers(mesh, connected_peer_cb, NULL);
525 if (WIFI_MESH_ERROR_NONE != ret) {
526 msgr("Failed to wifi_mesh_foreach_connected_peers: [%s(0x%X)]",
527 wifi_mesh_error_to_string(ret), ret);
530 msg(" - wifi_mesh_foreach_connected_peers() ret: [0x%X] [%s]",
531 ret, wifi_mesh_error_to_string(ret));
536 static int run_set_gate(MManager *mm, struct menu_data *menu)
539 bool _gate_announce = true;
540 int _hwmp_root_mode = 4;
543 msg("Set Gate Option");
545 if (strlen(gate_announce))
546 _gate_announce = (unsigned short)strtol(gate_announce, NULL, 16);
547 if (strlen(hwmp_root_mode))
548 _hwmp_root_mode = (unsigned short)strtol(hwmp_root_mode, NULL, 10);
550 _stp = (unsigned short)strtol(stp, NULL, 10);
552 ret = wifi_mesh_set_gate(mesh, _gate_announce, _hwmp_root_mode, _stp);
553 if (WIFI_MESH_ERROR_NONE != ret) {
554 msgr("Failed to set gate options: [%s(0x%X)]",
555 wifi_mesh_error_to_string(ret), ret);
558 msg(" - wifi_mesh_set_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
563 static int run_unset_gate(MManager *mm, struct menu_data *menu)
566 msg("Disable All Gate Option");
568 ret = wifi_mesh_unset_gate(mesh);
569 if (WIFI_MESH_ERROR_NONE != ret) {
570 msgr("Failed to unset gate option: [%s(0x%X)]",
571 wifi_mesh_error_to_string(ret), ret);
574 msg(" - wifi_mesh_unset_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
579 static int run_set_softap(MManager *mm, struct menu_data *menu)
584 int _max_stations = 10;
586 msg("Set SoftAp Option");
588 if (strlen(softap_channel))
589 _channel = (unsigned short)strtol(softap_channel, NULL, 10);
590 if (strlen(visibility)) {
591 _visibility = (unsigned short)strtol(visibility, NULL, 10);
592 if (1 != _visibility) _visibility = 0;
594 if (strlen(max_stations))
595 _max_stations = (unsigned short)strtol(max_stations, NULL, 10);
596 if (strlen(security))
597 _security = (unsigned short)strtol(security, NULL, 10);
599 ret = wifi_mesh_set_softap(mesh, ssid, passphrase,
600 _channel, _visibility, _max_stations, _security);
601 if (WIFI_MESH_ERROR_NONE != ret) {
602 msgr("Failed to set softap options: [%s(0x%X)]",
603 wifi_mesh_error_to_string(ret), ret);
606 msg(" - wifi_mesh_set_softap() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
608 msg("Get SoftAp Option");
609 char *g_ssid, *g_key;
610 int g_channel, g_max_stations, g_security;
612 ret = wifi_mesh_get_softap(mesh, &g_ssid, &g_channel, &g_visibility,
613 &g_max_stations, &g_security, &g_key);
614 if (WIFI_MESH_ERROR_NONE != ret) {
615 msgr("Failed to get softap options: [%s(0x%X)]",
616 wifi_mesh_error_to_string(ret), ret);
620 msg("SSID: %s", g_ssid);
621 msg("Channel: %d", g_channel);
622 msg("Visibility: %d", g_visibility);
623 msg("Max Stations: %d", g_max_stations);
624 msg("Security: %d", g_security);
625 msg("Key: %s", g_security ? g_key : "NULL");
633 static int run_enable_softap(MManager *mm, struct menu_data *menu)
636 msg("Enable SoftAp");
638 ret = wifi_mesh_enable_softap(mesh);
639 if (WIFI_MESH_ERROR_NONE != ret) {
640 msgr("Failed to enable soft ap: [%s(0x%X)]",
641 wifi_mesh_error_to_string(ret), ret);
644 msg(" - wifi_mesh_enable_softap() ret: [0x%X] [%s]",
645 ret, wifi_mesh_error_to_string(ret));
650 static int run_disable_softap(MManager *mm, struct menu_data *menu)
654 msg("Check SoftAp status");
656 ret = wifi_mesh_is_softap_started(mesh, &status);
657 if (WIFI_MESH_ERROR_NONE != ret) {
658 msgr("Failed to check soft ap status: [%s(0x%X)]",
659 wifi_mesh_error_to_string(ret), ret);
663 if (status == false) {
664 msg("SoftAP is already disabled");
668 msg("Disable SoftAp");
670 ret = wifi_mesh_disable_softap(mesh);
671 if (WIFI_MESH_ERROR_NONE != ret) {
672 msgr("Failed to disable soft ap: [%s(0x%X)]",
673 wifi_mesh_error_to_string(ret), ret);
676 msg(" - wifi_mesh_disable_softap() ret: [0x%X] [%s]",
677 ret, wifi_mesh_error_to_string(ret));
682 static int run_create_network(MManager *mm, struct menu_data *menu)
685 int _mesh_channel = 1;
686 wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
687 wifi_mesh_network_h net = NULL;
689 msg("Create a new Mesh Network");
691 if (strlen(mesh_channel))
692 _mesh_channel = (unsigned short)strtol(mesh_channel, NULL, 10);
694 if (strlen(mesh_security)) {
695 ret = (unsigned short)strtol(mesh_security, NULL, 10);
696 security = ((1 == ret) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE);
699 wifi_mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0,
700 security, security == MESH_SECURITY_SAE ? mesh_passphrase : NULL);
701 ret = wifi_mesh_create_network(mesh, net);
702 wifi_mesh_network_destroy(net);
703 if (WIFI_MESH_ERROR_NONE != ret) {
704 msgr("Failed to wifi_mesh_create_network: [%s(0x%X)]",
705 wifi_mesh_error_to_string(ret), ret);
708 msg(" - wifi_mesh_create_network() ret: [0x%X] [%s]",
709 ret, wifi_mesh_error_to_string(ret));
714 static int run_connect_network(MManager *mm, struct menu_data *menu)
718 wifi_mesh_network_h net = NULL;
719 wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
720 msg("Connect to Mesh Network");
722 if (strlen(network_idx)) {
723 idx = (unsigned short)strtol(network_idx, NULL, 10);
725 msgp("Invalid index. set to 1");
730 if (g_found_network_list) {
731 net = g_list_nth_data(g_found_network_list, idx - 1);
733 msgr("Failed to g_hash_table_find");
739 wifi_mesh_network_get_security(net, &security);
740 if (MESH_SECURITY_NONE != security) {
741 if (strlen(mesh_passphrase)) {
742 ret = wifi_mesh_network_set_passphrase(net, mesh_passphrase);
743 if (WIFI_MESH_ERROR_NONE != ret)
744 msgr("Failed to set passphrase !");
746 msgr("If security enabled, passphrase should be set !");
751 ret = wifi_mesh_connect_network(mesh, net);
752 if (WIFI_MESH_ERROR_NONE != ret) {
753 msgr("Failed to wifi_mesh_connect_network: [%s(0x%X)]",
754 wifi_mesh_error_to_string(ret), ret);
757 msg(" - wifi_mesh_connect_network() ret: [0x%X] [%s]",
758 ret, wifi_mesh_error_to_string(ret));
763 static int run_disconnect_network(MManager *mm, struct menu_data *menu)
767 wifi_mesh_network_h net = NULL;
768 msg("Disconnect with Mesh Network");
770 if (strlen(network_idx)) {
771 idx = (unsigned short)strtol(network_idx, NULL, 10);
773 msgp("Invalid index. set to 1");
778 if (g_found_network_list) {
779 net = g_list_nth_data(g_found_network_list, idx - 1);
781 msgr("Failed to g_hash_table_find");
786 ret = wifi_mesh_disconnect_network(mesh, net);
787 if (WIFI_MESH_ERROR_NONE != ret) {
788 msgr("Failed to wifi_mesh_disconnect_network: [%s(0x%X)]",
789 wifi_mesh_error_to_string(ret), ret);
792 msg(" - wifi_mesh_disconnect_network() ret: [0x%X] [%s]",
793 ret, wifi_mesh_error_to_string(ret));
798 static int run_forget_network(MManager *mm, struct menu_data *menu)
802 wifi_mesh_network_h net = NULL;
803 msg("Forget Mesh Network");
805 if (strlen(network_idx)) {
806 idx = (unsigned short)strtol(network_idx, NULL, 10);
808 msgp("Invalid index. set to 1");
813 if (g_found_network_list) {
814 net = g_list_nth_data(g_found_network_list, idx - 1);
816 msgr("Failed to g_hash_table_find");
821 ret = wifi_mesh_forget_network(mesh, net);
822 if (WIFI_MESH_ERROR_NONE != ret) {
823 msgr("Failed to wifi_mesh_forget_network: [%s(0x%X)]",
824 wifi_mesh_error_to_string(ret), ret);
827 msg(" - wifi_mesh_forget_network() ret: [0x%X] [%s]",
828 ret, wifi_mesh_error_to_string(ret));
833 static int run_get_station_information(MManager *mm, struct menu_data *menu)
836 msg("Get Mesh Station Information");
840 ret = wifi_mesh_get_stations_info(mesh, MESH_STATION_TYPE_MESH_POINT,
841 found_station_cb, NULL);
842 if (WIFI_MESH_ERROR_NONE != ret) {
843 msgr("Failed to wifi_mesh_get_stations_info: [%s(0x%X)]",
844 wifi_mesh_error_to_string(ret), ret);
847 msg(" - wifi_mesh_get_stations_info() ret: [0x%X] [%s]",
848 ret, wifi_mesh_error_to_string(ret));
853 static int run_get_mpath_information(MManager *mm, struct menu_data *menu)
856 msg("Get Mesh Path Information");
860 ret = wifi_mesh_get_mpath_info(mesh, found_mpath_cb, NULL);
861 if (WIFI_MESH_ERROR_NONE != ret) {
862 msgr("Failed to wifi_mesh_get_mpath_info: [%s(0x%X)]",
863 wifi_mesh_error_to_string(ret), ret);
866 msg(" - wifi_mesh_get_mpath_info() ret: [0x%X] [%s]",
867 ret, wifi_mesh_error_to_string(ret));
872 static int run_get_meshconf_information(MManager *mm, struct menu_data *menu)
875 wifi_mesh_meshconf_info_h meshconf;
876 gushort retry_timeout; /**< Retry Timeout */
877 guchar hwmp_max_preq_retries; /**< HWMP Max Preq Retries */
878 gushort confirm_timeout; /**< Confirm Timeout */
879 guint path_refresh_time; /**< Path Refresh Time */
880 gushort holding_timeout; /**< Holding Timeout */
881 gushort min_disc_timeout; /**< Min Discovery Timeout */
882 gushort max_peer_links; /**< Max Peer Links */
883 gushort hwmp_preq_min_interval; /**< HWMP PREQ Min Interval */
884 guchar ttl; /**< TTL */
885 guint hwmp_active_path_timeout; /**< HWMP Active Path Timeout */
886 guchar element_ttl; /**< Element TTL */
887 gushort hwmp_rann_interval; /**< HWMP RANN Interval */
888 guchar gate_announcements; /**< Gate Announcements */
889 msg("Get Mesh Conf Information");
893 ret = wifi_mesh_get_meshconf_info(mesh, &meshconf);
894 if (WIFI_MESH_ERROR_NONE != ret) {
895 msgr("Failed to wifi_mesh_get_meshconf_info: [%s(0x%X)]",
896 wifi_mesh_error_to_string(ret), ret);
900 msg("Mesh Configuration Informations:");
902 ret = wifi_mesh_get_meshconf_retry_timeout(meshconf, &retry_timeout);
903 if (WIFI_MESH_ERROR_NONE == ret)
904 msg("retry_timeout = %u", retry_timeout);
905 ret = wifi_mesh_get_meshconf_hwmp_max_preq_retries(meshconf,
906 &hwmp_max_preq_retries);
907 if (WIFI_MESH_ERROR_NONE == ret)
908 msg("hwmp_max_preq_retries = %u", hwmp_max_preq_retries);
909 ret = wifi_mesh_get_meshconf_confirm_timeout(meshconf, &confirm_timeout);
910 if (WIFI_MESH_ERROR_NONE == ret)
911 msg("confirm_timeout = %u", confirm_timeout);
912 ret = wifi_mesh_get_meshconf_path_refresh_time(meshconf,
914 if (WIFI_MESH_ERROR_NONE == ret)
915 msg("path_refresh_time = %u", path_refresh_time);
916 ret = wifi_mesh_get_meshconf_holding_timeout(meshconf, &holding_timeout);
917 if (WIFI_MESH_ERROR_NONE == ret)
918 msg("holding_timeout = %u", holding_timeout);
919 ret = wifi_mesh_get_meshconf_min_disc_timeout(meshconf, &min_disc_timeout);
920 if (WIFI_MESH_ERROR_NONE == ret)
921 msg("min_disc_timeout = %u", min_disc_timeout);
922 ret = wifi_mesh_get_meshconf_max_peer_links(meshconf, &max_peer_links);
923 if (WIFI_MESH_ERROR_NONE == ret)
924 msg("max_peer_links = %u", max_peer_links);
925 ret = wifi_mesh_get_meshconf_hwmp_preq_min_interval(meshconf,
926 &hwmp_preq_min_interval);
927 if (WIFI_MESH_ERROR_NONE == ret)
928 msg("hwmp_preq_min_interval = %u", hwmp_preq_min_interval);
929 ret = wifi_mesh_get_meshconf_ttl(meshconf, &ttl);
930 if (WIFI_MESH_ERROR_NONE == ret)
931 msg("ttl = %u", ttl);
932 ret = wifi_mesh_get_meshconf_hwmp_active_path_timeout(meshconf,
933 &hwmp_active_path_timeout);
934 if (WIFI_MESH_ERROR_NONE == ret)
935 msg("hwmp_active_path_timeout = %u", hwmp_active_path_timeout);
936 ret = wifi_mesh_get_meshconf_element_ttl(meshconf, &element_ttl);
937 if (WIFI_MESH_ERROR_NONE == ret)
938 msg("element_ttl = %u", element_ttl);
939 ret = wifi_mesh_get_meshconf_hwmp_rann_interval(meshconf,
940 &hwmp_rann_interval);
941 if (WIFI_MESH_ERROR_NONE == ret)
942 msg("hwmp_rann_interval = %u", hwmp_rann_interval);
943 ret = wifi_mesh_get_meshconf_gate_announcements(meshconf,
944 &gate_announcements);
945 if (WIFI_MESH_ERROR_NONE == ret)
946 msg("gate_announcements = %u", gate_announcements);
948 ret = wifi_mesh_destroy_meshconf_info(meshconf);
949 if (WIFI_MESH_ERROR_NONE != ret) {
950 msgr("Failed to wifi_mesh_destroy_meshconf_info: [%s(0x%X)]",
951 wifi_mesh_error_to_string(ret), ret);
954 msg("Successfully destroyed meshconf info");
959 static int run_get_softap_station_info(MManager *mm, struct menu_data *menu)
962 msg("Get SoftAP Station Information");
966 ret = wifi_mesh_get_stations_info(mesh, MESH_STATION_TYPE_SOFTAP,
967 found_station_cb, NULL);
968 if (WIFI_MESH_ERROR_NONE != ret) {
969 msgr("Failed to wifi_mesh_get_stations_info: [%s(0x%X)]",
970 wifi_mesh_error_to_string(ret), ret);
973 msg(" - wifi_mesh_get_stations_info() ret: [0x%X] [%s]",
974 ret, wifi_mesh_error_to_string(ret));
979 static struct menu_data menu_specific_scan[] = {
980 { "1", "Mesh ID", NULL, NULL, meshid },
981 { "2", "Channel", NULL, NULL, mesh_channel },
982 { "3", "Run", NULL, run_wifi_mesh_specific_scan, NULL },
986 static struct menu_data menu_gate_option[] = {
987 { "1", "Gate Announcement", NULL, NULL, gate_announce },
988 { "2", "HWMP Root Mode", NULL, NULL, hwmp_root_mode },
989 { "3", "STP", NULL, NULL, stp },
990 { "4", "Run", NULL, run_set_gate, NULL },
994 static struct menu_data menu_softap_option[] = {
995 { "1", "SSID", NULL, NULL, ssid },
996 { "2", "passphrase", NULL, NULL, passphrase },
997 { "3", "802.11 mode", NULL, NULL, mode },
998 { "4", "channel", NULL, NULL, softap_channel },
999 { "5", "SSID broadcast=1, hidden=0", NULL, NULL, visibility },
1000 { "6", "max. client num", NULL, NULL, max_stations },
1001 { "6", "security (wpa1=1, wpa2=2)", NULL, NULL, security },
1002 { "7", "run", NULL, run_set_softap, NULL },
1006 static struct menu_data menu_create_network[] = {
1007 { "1", "Mesh ID", NULL, NULL, meshid },
1008 { "2", "Channel", NULL, NULL, mesh_channel },
1009 { "3", "Security (0=None,1=SAE)", NULL, NULL, mesh_security },
1010 { "4", "Passphrase", NULL, NULL, mesh_passphrase },
1011 { "5", "Run", NULL, run_create_network, NULL },
1015 static struct menu_data menu_connect_network[] = {
1016 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
1017 { "1", "Index", NULL, NULL, network_idx },
1018 { "2", "Passphrase", NULL, NULL, mesh_passphrase },
1019 { "3", "Run", NULL, run_connect_network, NULL },
1023 static struct menu_data menu_disconnect_network[] = {
1024 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
1025 { "1", "Index", NULL, NULL, network_idx },
1026 { "2", "Run", NULL, run_disconnect_network, NULL },
1030 static struct menu_data menu_forget_network[] = {
1031 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
1032 { "1", "Index", NULL, NULL, network_idx },
1033 { "2", "Run", NULL, run_forget_network, NULL },
1038 struct menu_data menu_mesh_network[] = {
1039 { "1", "Start", NULL, run_wifi_mesh_enable, NULL },
1040 { "2", "Stop", NULL, run_wifi_mesh_disable, NULL },
1041 { "3", "Scan", NULL, run_wifi_mesh_scan, NULL },
1042 { "4", "Specific scan", menu_specific_scan, NULL, NULL },
1043 { "5", "Cancel scan", NULL, run_wifi_mesh_cancel_scan, NULL },
1044 { "6", "Get found mesh network", NULL, run_get_found_mesh_network, NULL },
1045 { "7", "Create network", menu_create_network, NULL, NULL },
1046 { "8", "Connect network", menu_connect_network, NULL, NULL },
1047 { "9", "Disconnect network", menu_disconnect_network, NULL, NULL },
1048 { "10", "Forget network", menu_forget_network, NULL, NULL },
1049 { "11", "Get joined mesh network", NULL, run_get_joined_mesh_network, NULL },
1050 { "12", "Set softap", menu_softap_option, NULL, NULL },
1051 { "13", "Enable softap", NULL, run_enable_softap, NULL },
1052 { "14", "Disable softap", NULL, run_disable_softap, NULL },
1053 { "15", "Get connected mesh peers", NULL, run_get_connected_peers, NULL },
1054 { "16", "Set gate", menu_gate_option, NULL, NULL },
1055 { "17", "Unset gate", NULL, run_unset_gate, NULL },
1056 { "18", "Get mesh station information", NULL, run_get_station_information, NULL },
1057 { "19", "Get mesh path information", NULL, run_get_mpath_information, NULL },
1058 { "20", "Get mesh conf information", NULL, run_get_meshconf_information,
1060 { "21", "Get softap station information", NULL, run_get_softap_station_info,