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;
55 static void found_mesh_network_cb(wifi_mesh_network_h network, void* user_data)
58 wifi_mesh_network_h net = NULL;
63 wifi_mesh_security_type_e security;
66 ret = wifi_mesh_network_clone(&net, network);
67 if (WIFI_MESH_ERROR_NONE != ret) {
68 msgr("Failed to clone found network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
72 g_found_network_list = g_list_append(g_found_network_list, net);
74 wifi_mesh_network_get_meshid(net, &meshid);
75 wifi_mesh_network_get_bssid(net, &bssid);
76 wifi_mesh_network_get_channel(net, &channel);
77 wifi_mesh_network_get_rssi(net, &rssi);
78 wifi_mesh_network_get_data_rate(net, &data_rate);
79 wifi_mesh_network_get_security(net, &security);
80 msgb(" [%02d] Mesh ID[%-10s] BSSID[%s] Channel[%d] RSSI[%ddBm] Date Rate[%dMbps] Security[%4s]",
81 g_scan_net_idx, meshid, bssid, channel, rssi == 0 ? 0 : rssi-120, data_rate,
82 (MESH_SECURITY_SAE == security) ? "SAE" : "NONE");
86 if (meshid) free(meshid);
87 if (bssid) free(bssid);
90 static void connected_peer_cb(wifi_mesh_peer_h peer, void* user_data)
94 wifi_mesh_peer_get_address(peer, &address);
95 msgb(" Peer Address [%s]", address);
101 static void found_station_cb(wifi_mesh_station_info_h station, void* user_data)
103 int ret = WIFI_MESH_ERROR_NONE;
104 gchar *bssid = NULL; /* station bssid ex) 7c:dd:90:62:37:cf (on mesh0) */
105 guint inactive_time; /**< inactive time ex) 1685 ms */
106 guint64 rx_bytes; /**< rx bytes ex) 34174 */
107 guint rx_packets; /**< rx packet ex) 1181 */
108 guint64 tx_bytes; /**< tx bytes ex) 6877 */
109 guint tx_packets; /**< tx packets ex) 76 */
110 guint tx_retries; /**< tx retries ex) 0 */
111 guint tx_failed; /**< tx failed ex) 0 */
112 guint beacon_loss; /**< beacon loss count ex) 0 */
113 guint64 beacon_rx; /**< beacon rx ex) 0 */
114 guint64 rx_drop_misc; /**< rx drop misc ex) 0 */
115 gint signal; /**< Signal ex) -64 dBm */
116 gint signal_avg; /**< Average Signal ex) -63 dBm */
117 guint tx_bitrate; /**< tx bitrate ex) 54.0 MBit/s => 540 */
118 guint rx_bitrate; /**< rx bitrate ex) 5.5 MBit/s => 55 */
119 gushort mesh_llid; /**< mesh_llid ex) 51731 */
120 gushort mesh_plid; /**< mesh plid ex) 35432 */
121 guchar mesh_plink; /**< mesh plink ex) ESTAB */
122 guint local_ps_mode; /**< mesh local power save mode ex) ACTIVE */
123 guint peer_ps_mode; /**< mesh peer power save mode ex) ACTIVE */
124 guint non_peer_ps_mode; /**< mesh non-peer power save mode ex) ACTIVE */
125 gboolean authorized; /**< authorized ex) yes */
126 gboolean authenticated; /**< authenticated ex) yes */
127 gboolean associated; /**< associated ex) yes */
128 gboolean preamble; /**< preamble ex) long */
129 gboolean wmm_wme; /**< WMM/WME supported ex) yes */
130 gboolean mfp; /**< MFP ex) no */
131 gboolean tdls_peer; /**< TDLS peer ex) no */
132 guchar dtim_period; /**< DTIM period ex) 0 */
133 gushort beacon_interval; /**< beacon interval ex) 1000 */
134 gboolean cts_protection; /**< CTS protection */
135 gboolean short_preamble; /**< short preamble */
136 gboolean short_slot_time; /**< short slot time supported ex) yes */
137 guint connected_time; /**< connected time : ex) 256 seconds */
139 msg("Station Information Received: %p", station);
144 ret = wifi_mesh_get_sta_bssid(station, bssid);
145 if (WIFI_MESH_ERROR_NONE == ret)
146 msg("bssid = %s", bssid);
147 ret = wifi_mesh_get_sta_inactive_time(station, &inactive_time);
148 if (WIFI_MESH_ERROR_NONE == ret)
149 msg("inactive_time = %d", inactive_time);
150 ret = wifi_mesh_get_sta_rx_bytes(station, &rx_bytes);
151 if (WIFI_MESH_ERROR_NONE == ret)
152 msg("rx_bytes = %lld", rx_bytes);
153 ret = wifi_mesh_get_sta_rx_packets(station, &rx_packets);
154 if (WIFI_MESH_ERROR_NONE == ret)
155 msg("rx_packets = %d", rx_packets);
156 ret = wifi_mesh_get_sta_tx_bytes(station, &tx_bytes);
157 if (WIFI_MESH_ERROR_NONE == ret)
158 msg("tx_bytes = %lld", tx_bytes);
159 ret = wifi_mesh_get_sta_tx_packets(station, &tx_packets);
160 if (WIFI_MESH_ERROR_NONE == ret)
161 msg("tx_bytes = %lld", tx_bytes);
162 ret = wifi_mesh_get_sta_tx_retries(station, &tx_retries);
163 if (WIFI_MESH_ERROR_NONE == ret)
164 msg("tx_bytes = %lld", tx_bytes);
165 ret = wifi_mesh_get_sta_tx_failed(station, &tx_failed);
166 if (WIFI_MESH_ERROR_NONE == ret)
167 msg("tx_failed = %d", tx_failed);
168 ret = wifi_mesh_get_sta_beacon_loss(station, &beacon_loss);
169 if (WIFI_MESH_ERROR_NONE == ret)
170 msg("beacon_loss = %d", beacon_loss);
171 ret = wifi_mesh_get_sta_beacon_rx(station, &beacon_rx);
172 if (WIFI_MESH_ERROR_NONE == ret)
173 msg("beacon_rx = %lld", beacon_rx);
174 ret = wifi_mesh_get_sta_rx_drop_misc(station, &rx_drop_misc);
175 if (WIFI_MESH_ERROR_NONE == ret)
176 msg("rx_drop_misc = %lld", rx_drop_misc);
177 ret = wifi_mesh_get_sta_signal(station, &signal);
178 if (WIFI_MESH_ERROR_NONE == ret)
179 msg("signal = %d", signal);
180 ret = wifi_mesh_get_sta_signal_avg(station, &signal_avg);
181 if (WIFI_MESH_ERROR_NONE == ret)
182 msg("signal_avg = %d", signal_avg);
183 ret = wifi_mesh_get_sta_tx_bitrate(station, &tx_bitrate);
184 if (WIFI_MESH_ERROR_NONE == ret)
185 msg("inactive_time = %d", inactive_time);
186 ret = wifi_mesh_get_sta_rx_bitrate(station, &rx_bitrate);
187 if (WIFI_MESH_ERROR_NONE == ret)
188 msg("tx_bitrate = %d", tx_bitrate);
189 ret = wifi_mesh_get_sta_mesh_llid(station, &mesh_llid);
190 if (WIFI_MESH_ERROR_NONE == ret)
191 msg("mesh_llid = %d", mesh_llid);
192 ret = wifi_mesh_get_sta_mesh_plid(station, &mesh_plid);
193 if (WIFI_MESH_ERROR_NONE == ret)
194 msg("mesh_plid = %d", mesh_plid);
195 ret = wifi_mesh_get_sta_mesh_plink(station, &mesh_plink);
196 if (WIFI_MESH_ERROR_NONE == ret)
197 msg("inactive_time = %d", inactive_time);
198 ret = wifi_mesh_get_sta_local_ps_mode(station, &local_ps_mode);
199 if (WIFI_MESH_ERROR_NONE == ret)
200 msg("inactive_time = %d", inactive_time);
201 ret = wifi_mesh_get_sta_peer_ps_mode(station, &peer_ps_mode);
202 if (WIFI_MESH_ERROR_NONE == ret)
203 msg("local_ps_mode = %d", local_ps_mode);
204 ret = wifi_mesh_get_sta_non_peer_ps_mode(station, &non_peer_ps_mode);
205 if (WIFI_MESH_ERROR_NONE == ret)
206 msg("local_ps_mode = %d", local_ps_mode);
207 ret = wifi_mesh_get_sta_authorized(station, &authorized);
208 if (WIFI_MESH_ERROR_NONE == ret)
209 msg("authorized = %d", authorized);
210 ret = wifi_mesh_get_sta_authenticated(station, &authenticated);
211 if (WIFI_MESH_ERROR_NONE == ret)
212 msg("authenticated = %d", authenticated);
213 ret = wifi_mesh_get_sta_associated(station, &associated);
214 if (WIFI_MESH_ERROR_NONE == ret)
215 msg("associated = %d", associated);
216 ret = wifi_mesh_get_sta_preamble(station, &preamble);
217 if (WIFI_MESH_ERROR_NONE == ret)
218 msg("preamble = %d", preamble);
219 ret = wifi_mesh_get_sta_wmm_wme(station, &wmm_wme);
220 if (WIFI_MESH_ERROR_NONE == ret)
221 msg("wmm_wme = %d", wmm_wme);
222 ret = wifi_mesh_get_sta_mfp(station, &mfp);
223 if (WIFI_MESH_ERROR_NONE == ret)
224 msg("wmm_wme = %d", wmm_wme);
225 ret = wifi_mesh_get_sta_tdls_peer(station, &tdls_peer);
226 if (WIFI_MESH_ERROR_NONE == ret)
227 msg("tdls_peer = %d", tdls_peer);
228 ret = wifi_mesh_get_sta_dtim_period(station, &dtim_period);
229 if (WIFI_MESH_ERROR_NONE == ret)
230 msg("dtim_period = %d", dtim_period);
231 ret = wifi_mesh_get_sta_beacon_interval(station, &beacon_interval);
232 if (WIFI_MESH_ERROR_NONE == ret)
233 msg("beacon_interval = %d", beacon_interval);
234 ret = wifi_mesh_get_sta_cts_protection(station, &cts_protection);
235 if (WIFI_MESH_ERROR_NONE == ret)
236 msg("cts_protection = %d", cts_protection);
237 ret = wifi_mesh_get_sta_short_preamble(station, &short_preamble);
238 if (WIFI_MESH_ERROR_NONE == ret)
239 msg("short_preamble = %d", short_preamble);
240 ret = wifi_mesh_get_sta_short_slot_time(station, &short_slot_time);
241 if (WIFI_MESH_ERROR_NONE == ret)
242 msg("short_slot_time = %d", short_slot_time);
243 ret = wifi_mesh_get_sta_connected_time(station, &connected_time);
244 if (WIFI_MESH_ERROR_NONE == ret)
245 msg("connected_time = %d", connected_time);
249 static void found_mpath_cb(wifi_mesh_mpath_info_h mpath, void* user_data)
251 int ret = WIFI_MESH_ERROR_NONE;
253 gchar dest_addr[MAX_BSSID_LEN]; /**< destination address */
254 gchar next_hop[MAX_BSSID_LEN]; /**< next hop address */
255 gchar iface[32]; /**< network interface for mesh */
256 guint sn; /**< sequence number */
257 guint metric; /**< metric */
258 guint qlen; /**< driver queue length */
259 guint exptime; /**< expire time */
260 guint discovery_timeout; /**< Discovery timeout */
261 guchar discovery_retries; /**< Discovery retries */
262 guchar flags; /**< Flags */
264 msg("Station Information Received: %p", mpath);
266 ret = wifi_mesh_get_mpath_dest_addr(mpath, dest_addr);
267 if (WIFI_MESH_ERROR_NONE == ret)
268 msg("dest_addr = %s", dest_addr);
269 ret = wifi_mesh_get_mpath_next_hop(mpath, next_hop);
270 if (WIFI_MESH_ERROR_NONE == ret)
271 msg("next_hop = %s", next_hop);
272 ret = wifi_mesh_get_mpath_iface(mpath, iface);
273 if (WIFI_MESH_ERROR_NONE == ret)
274 msg("iface = %s", iface);
275 ret = wifi_mesh_get_mpath_sn(mpath, &sn);
276 if (WIFI_MESH_ERROR_NONE == ret)
278 ret = wifi_mesh_get_mpath_metric(mpath, &metric);
279 if (WIFI_MESH_ERROR_NONE == ret)
280 msg("metric = %d", metric);
281 ret = wifi_mesh_get_mpath_qlen(mpath, &qlen);
282 if (WIFI_MESH_ERROR_NONE == ret)
283 msg("qlen = %d", qlen);
284 ret = wifi_mesh_get_mpath_exptime(mpath, &exptime);
285 if (WIFI_MESH_ERROR_NONE == ret)
286 msg("exptime = %d", exptime);
287 ret = wifi_mesh_get_mpath_disc_timeout(mpath, &discovery_timeout);
288 if (WIFI_MESH_ERROR_NONE == ret)
289 msg("discovery_timeout = %d", discovery_timeout);
290 ret = wifi_mesh_get_mpath_disc_retries(mpath, &discovery_retries);
291 if (WIFI_MESH_ERROR_NONE == ret)
292 msg("discovery_retries = %d", discovery_retries);
293 ret = wifi_mesh_get_mpath_flags(mpath, &flags);
294 if (WIFI_MESH_ERROR_NONE == ret)
295 msg("flags = %d", flags);
299 static int run_show_found_network(MManager *mm, struct menu_data *menu)
301 int i = 1; /* Displays from 1 */
302 char *_meshid = NULL;
304 wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
308 if (NULL == g_found_network_list) {
309 msgp("There is not any scan result.. do scan first");
313 msg("Scan Results : ");
314 iter = g_found_network_list;
315 while (iter != NULL) {
316 wifi_mesh_network_h _net = iter->data;
317 wifi_mesh_network_get_meshid(_net, &_meshid);
318 wifi_mesh_network_get_channel(_net, &_channel);
319 wifi_mesh_network_get_security(_net, &_security);
320 msgb(" [%02d] Mesh ID[%-10s] Channel[%d] Security[%4s]", i++,
321 _meshid, _channel, (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE");
323 if (_meshid) free(_meshid);
325 iter = g_list_next(iter);
332 static int run_wifi_mesh_scan(MManager *mm, struct menu_data *menu)
337 ret = wifi_mesh_scan(mesh);
338 if (WIFI_MESH_ERROR_NONE != ret) {
339 msgr("Failed to scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
342 msg(" - wifi_mesh_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
347 static int run_get_found_mesh_network(MManager *mm, struct menu_data *menu)
350 msg("Get Found Mesh Network");
352 /* Clear previous found network list */
354 if (g_found_network_list)
355 g_list_free_full(g_found_network_list, (void *)wifi_mesh_network_destroy);
357 g_found_network_list = NULL;
359 ret = wifi_mesh_foreach_found_network(mesh, found_mesh_network_cb, NULL);
360 if (WIFI_MESH_ERROR_NONE != ret) {
361 msgr("Failed to wifi_mesh_foreach_found_network: [%s(0x%X)]",
362 wifi_mesh_error_to_string(ret), ret);
365 msg(" - wifi_mesh_foreach_found_network() ret: [0x%X] [%s]",
366 ret, wifi_mesh_error_to_string(ret));
371 static int run_wifi_mesh_specific_scan(MManager *mm, struct menu_data *menu)
376 msg("Specific scan");
378 if (strlen(mesh_channel))
379 channel = (unsigned short)strtol(mesh_channel, NULL, 10);
381 ret = wifi_mesh_specific_scan(mesh, meshid, channel);
382 if (WIFI_MESH_ERROR_NONE != ret) {
383 msgr("Failed to specific scan: [%s(0x%X)]",
384 wifi_mesh_error_to_string(ret), ret);
387 msg(" - wifi_mesh_specific_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
392 static int run_wifi_mesh_cancel_scan(MManager *mm, struct menu_data *menu)
397 ret = wifi_mesh_cancel_scan(mesh);
398 if (WIFI_MESH_ERROR_NONE != ret) {
399 msgr("Failed to cancel scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
402 msg(" - wifi_mesh_cancel_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
407 static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu)
412 ret = wifi_mesh_start(mesh);
413 if (WIFI_MESH_ERROR_NONE != ret) {
414 msgr("Failed to enable mesh network: [%s(0x%X)]",
415 wifi_mesh_error_to_string(ret), ret);
418 msg(" - wifi_mesh_start() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
423 static int run_wifi_mesh_disable(MManager *mm, struct menu_data *menu)
428 ret = wifi_mesh_stop(mesh);
429 if (WIFI_MESH_ERROR_NONE != ret) {
430 msgr("Failed to disable mesh network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
433 msg(" - wifi_mesh_stop() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
438 static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu)
441 char *_meshid = NULL;
445 wifi_mesh_connection_state_e _state = WIFI_MESH_CONNECTION_STATE_DISCONNECTED;
446 wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
447 wifi_mesh_network_h network = NULL;
449 msg("Get Joined Mesh Network Information");
451 ret = wifi_mesh_is_joined(mesh, &joined);
452 if (WIFI_MESH_ERROR_NONE != ret) {
453 msgr("Failed to check network join status: [%s(0x%X)]",
454 wifi_mesh_error_to_string(ret), ret);
458 ret = wifi_mesh_get_joined_network(mesh, &network);
459 if (WIFI_MESH_ERROR_NONE != ret) {
460 msgr("Failed to get joined mesh network: [%s(0x%X)]",
461 wifi_mesh_error_to_string(ret), ret);
465 if (NULL != network) {
466 wifi_mesh_network_get_meshid(network, &_meshid);
467 msgb(" Mesh ID = %s", _meshid);
468 wifi_mesh_network_get_bssid(network, &_bssid);
469 msgb(" BSSID = %s", _bssid);
470 wifi_mesh_network_get_channel(network, &_channel);
471 msgb(" Channel = %d", _channel);
472 wifi_mesh_network_get_security(network, &_security);
473 msgb(" Security = %s",
474 (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE");
475 wifi_mesh_network_get_connection_state(network, &_state);
476 msgb(" State = %s", wifi_mesh_connection_event_to_string(_state));
478 if (_meshid) free(_meshid);
479 if (_bssid) free(_bssid);
482 msg(" - wifi_mesh_get_joined_network() ret: [0x%X] [%s]",
483 ret, wifi_mesh_error_to_string(ret));
488 static int run_get_connected_peers(MManager *mm, struct menu_data *menu)
491 msg("Get Connected Mesh Peers");
493 ret = wifi_mesh_foreach_connected_peers(mesh, connected_peer_cb, NULL);
494 if (WIFI_MESH_ERROR_NONE != ret) {
495 msgr("Failed to wifi_mesh_foreach_connected_peers: [%s(0x%X)]",
496 wifi_mesh_error_to_string(ret), ret);
499 msg(" - wifi_mesh_foreach_connected_peers() ret: [0x%X] [%s]",
500 ret, wifi_mesh_error_to_string(ret));
505 static int run_set_gate(MManager *mm, struct menu_data *menu)
508 bool _gate_announce = true;
509 int _hwmp_root_mode = 4;
512 msg("Set Gate Option");
514 if (strlen(gate_announce))
515 _gate_announce = (unsigned short)strtol(gate_announce, NULL, 16);
516 if (strlen(hwmp_root_mode))
517 _hwmp_root_mode = (unsigned short)strtol(hwmp_root_mode, NULL, 10);
519 _stp = (unsigned short)strtol(stp, NULL, 10);
521 ret = wifi_mesh_set_gate(mesh, _gate_announce, _hwmp_root_mode, _stp);
522 if (WIFI_MESH_ERROR_NONE != ret) {
523 msgr("Failed to set gate options: [%s(0x%X)]",
524 wifi_mesh_error_to_string(ret), ret);
527 msg(" - wifi_mesh_set_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
532 static int run_unset_gate(MManager *mm, struct menu_data *menu)
535 msg("Disable All Gate Option");
537 ret = wifi_mesh_unset_gate(mesh);
538 if (WIFI_MESH_ERROR_NONE != ret) {
539 msgr("Failed to unset gate option: [%s(0x%X)]",
540 wifi_mesh_error_to_string(ret), ret);
543 msg(" - wifi_mesh_unset_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
548 static int run_set_softap(MManager *mm, struct menu_data *menu)
553 int _max_stations = 10;
555 msg("Set SoftAp Option");
557 if (strlen(softap_channel))
558 _channel = (unsigned short)strtol(softap_channel, NULL, 10);
559 if (strlen(visibility)) {
560 _visibility = (unsigned short)strtol(visibility, NULL, 10);
561 if (1 != _visibility) _visibility = 0;
563 if (strlen(max_stations))
564 _max_stations = (unsigned short)strtol(max_stations, NULL, 10);
565 if (strlen(security))
566 _security = (unsigned short)strtol(security, NULL, 10);
568 ret = wifi_mesh_set_softap(mesh, ssid, passphrase,
569 _channel, _visibility, _max_stations, _security);
570 if (WIFI_MESH_ERROR_NONE != ret) {
571 msgr("Failed to set softap options: [%s(0x%X)]",
572 wifi_mesh_error_to_string(ret), ret);
575 msg(" - wifi_mesh_set_softap() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
580 static int run_enable_softap(MManager *mm, struct menu_data *menu)
583 msg("Enable SoftAp");
585 ret = wifi_mesh_enable_softap(mesh);
586 if (WIFI_MESH_ERROR_NONE != ret) {
587 msgr("Failed to enable soft ap: [%s(0x%X)]",
588 wifi_mesh_error_to_string(ret), ret);
591 msg(" - wifi_mesh_enable_softap() ret: [0x%X] [%s]",
592 ret, wifi_mesh_error_to_string(ret));
597 static int run_disable_softap(MManager *mm, struct menu_data *menu)
600 msg("Disable SoftAp");
602 ret = wifi_mesh_disable_softap(mesh);
603 if (WIFI_MESH_ERROR_NONE != ret) {
604 msgr("Failed to disable soft ap: [%s(0x%X)]",
605 wifi_mesh_error_to_string(ret), ret);
608 msg(" - wifi_mesh_disable_softap() ret: [0x%X] [%s]",
609 ret, wifi_mesh_error_to_string(ret));
614 static int run_create_network(MManager *mm, struct menu_data *menu)
617 int _mesh_channel = 1;
618 wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
619 wifi_mesh_network_h net = NULL;
621 msg("Create a new Mesh Network");
623 if (strlen(mesh_channel))
624 _mesh_channel = (unsigned short)strtol(mesh_channel, NULL, 10);
626 if (strlen(mesh_security)) {
627 ret = (unsigned short)strtol(mesh_security, NULL, 10);
628 security = ((1 == ret) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE);
631 wifi_mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0,
632 security, security == MESH_SECURITY_SAE ? mesh_passphrase : NULL);
633 ret = wifi_mesh_create_network(mesh, net);
634 wifi_mesh_network_destroy(net);
635 if (WIFI_MESH_ERROR_NONE != ret) {
636 msgr("Failed to wifi_mesh_create_network: [%s(0x%X)]",
637 wifi_mesh_error_to_string(ret), ret);
640 msg(" - wifi_mesh_create_network() ret: [0x%X] [%s]",
641 ret, wifi_mesh_error_to_string(ret));
646 static int run_connect_network(MManager *mm, struct menu_data *menu)
650 wifi_mesh_network_h net = NULL;
651 wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
652 msg("Connect to Mesh Network");
654 if (strlen(network_idx)) {
655 idx = (unsigned short)strtol(network_idx, NULL, 10);
657 msgp("Invalid index. set to 1");
662 if (g_found_network_list) {
663 net = g_list_nth_data(g_found_network_list, idx - 1);
665 msgr("Failed to g_hash_table_find");
671 wifi_mesh_network_get_security(net, &security);
672 if (MESH_SECURITY_NONE != security) {
673 if (strlen(mesh_passphrase)) {
674 ret = wifi_mesh_network_set_passphrase(net, mesh_passphrase);
675 if (WIFI_MESH_ERROR_NONE != ret)
676 msgr("Failed to set passphrase !");
678 msgr("If security enabled, passphrase should be set !");
683 ret = wifi_mesh_connect_network(mesh, net);
684 if (WIFI_MESH_ERROR_NONE != ret) {
685 msgr("Failed to wifi_mesh_connect_network: [%s(0x%X)]",
686 wifi_mesh_error_to_string(ret), ret);
689 msg(" - wifi_mesh_connect_network() ret: [0x%X] [%s]",
690 ret, wifi_mesh_error_to_string(ret));
695 static int run_disconnect_network(MManager *mm, struct menu_data *menu)
699 wifi_mesh_network_h net = NULL;
700 msg("Disconnect with Mesh Network");
702 if (strlen(network_idx)) {
703 idx = (unsigned short)strtol(network_idx, NULL, 10);
705 msgp("Invalid index. set to 1");
710 if (g_found_network_list) {
711 net = g_list_nth_data(g_found_network_list, idx - 1);
713 msgr("Failed to g_hash_table_find");
718 ret = wifi_mesh_disconnect_network(mesh, net);
719 if (WIFI_MESH_ERROR_NONE != ret) {
720 msgr("Failed to wifi_mesh_disconnect_network: [%s(0x%X)]",
721 wifi_mesh_error_to_string(ret), ret);
724 msg(" - wifi_mesh_disconnect_network() ret: [0x%X] [%s]",
725 ret, wifi_mesh_error_to_string(ret));
730 static int run_forget_network(MManager *mm, struct menu_data *menu)
734 wifi_mesh_network_h net = NULL;
735 msg("Forget Mesh Network");
737 if (strlen(network_idx)) {
738 idx = (unsigned short)strtol(network_idx, NULL, 10);
740 msgp("Invalid index. set to 1");
745 if (g_found_network_list) {
746 net = g_list_nth_data(g_found_network_list, idx - 1);
748 msgr("Failed to g_hash_table_find");
753 ret = wifi_mesh_forget_network(mesh, net);
754 if (WIFI_MESH_ERROR_NONE != ret) {
755 msgr("Failed to wifi_mesh_forget_network: [%s(0x%X)]",
756 wifi_mesh_error_to_string(ret), ret);
759 msg(" - wifi_mesh_forget_network() ret: [0x%X] [%s]",
760 ret, wifi_mesh_error_to_string(ret));
765 static int run_get_station_information(MManager *mm, struct menu_data *menu)
768 msg("Get Mesh Station Information");
770 ret = wifi_mesh_get_stations_info(mesh, found_station_cb, NULL);
771 if (WIFI_MESH_ERROR_NONE != ret) {
772 msgr("Failed to wifi_mesh_get_stations_info: [%s(0x%X)]",
773 wifi_mesh_error_to_string(ret), ret);
776 msg(" - wifi_mesh_get_stations_info() ret: [0x%X] [%s]",
777 ret, wifi_mesh_error_to_string(ret));
782 static int run_get_mpath_information(MManager *mm, struct menu_data *menu)
785 msg("Get Mesh Path Information");
787 ret = wifi_mesh_get_mpath_info(mesh, found_mpath_cb, NULL);
788 if (WIFI_MESH_ERROR_NONE != ret) {
789 msgr("Failed to wifi_mesh_get_mpath_info: [%s(0x%X)]",
790 wifi_mesh_error_to_string(ret), ret);
793 msg(" - wifi_mesh_get_mpath_info() ret: [0x%X] [%s]",
794 ret, wifi_mesh_error_to_string(ret));
798 static struct menu_data menu_specific_scan[] = {
799 { "1", "Mesh ID", NULL, NULL, meshid },
800 { "2", "Channel", NULL, NULL, mesh_channel },
801 { "3", "Run", NULL, run_wifi_mesh_specific_scan, NULL },
805 static struct menu_data menu_gate_option[] = {
806 { "1", "Gate Announcement", NULL, NULL, gate_announce },
807 { "2", "HWMP Root Mode", NULL, NULL, hwmp_root_mode },
808 { "3", "STP", NULL, NULL, stp },
809 { "4", "Run", NULL, run_set_gate, NULL },
813 static struct menu_data menu_softap_option[] = {
814 { "1", "SSID", NULL, NULL, ssid },
815 { "2", "passphrase", NULL, NULL, passphrase },
816 { "3", "802.11 mode", NULL, NULL, mode },
817 { "4", "channel", NULL, NULL, softap_channel },
818 { "5", "SSID broadcast=1, hidden=0", NULL, NULL, visibility },
819 { "6", "max. client num", NULL, NULL, max_stations },
820 { "6", "security (wpa1=1, wpa2=2)", NULL, NULL, security },
821 { "7", "run", NULL, run_set_softap, NULL },
825 static struct menu_data menu_create_network[] = {
826 { "1", "Mesh ID", NULL, NULL, meshid },
827 { "2", "Channel", NULL, NULL, mesh_channel },
828 { "3", "Security (0=None,1=SAE)", NULL, NULL, mesh_security },
829 { "4", "Passphrase", NULL, NULL, mesh_passphrase },
830 { "5", "Run", NULL, run_create_network, NULL },
834 static struct menu_data menu_connect_network[] = {
835 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
836 { "1", "Index", NULL, NULL, network_idx },
837 { "2", "Passphrase", NULL, NULL, mesh_passphrase },
838 { "3", "Run", NULL, run_connect_network, NULL },
842 static struct menu_data menu_disconnect_network[] = {
843 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
844 { "1", "Index", NULL, NULL, network_idx },
845 { "2", "Run", NULL, run_disconnect_network, NULL },
849 static struct menu_data menu_forget_network[] = {
850 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
851 { "1", "Index", NULL, NULL, network_idx },
852 { "2", "Run", NULL, run_forget_network, NULL },
857 struct menu_data menu_mesh_network[] = {
858 { "1", "Start", NULL, run_wifi_mesh_enable, NULL },
859 { "2", "Stop", NULL, run_wifi_mesh_disable, NULL },
860 { "3", "Scan", NULL, run_wifi_mesh_scan, NULL },
861 { "4", "Specific scan", menu_specific_scan, NULL, NULL },
862 { "5", "Cancel scan", NULL, run_wifi_mesh_cancel_scan, NULL },
863 { "6", "Get found mesh network", NULL, run_get_found_mesh_network, NULL },
864 { "7", "Create network", menu_create_network, NULL, NULL },
865 { "8", "Connect network", menu_connect_network, NULL, NULL },
866 { "9", "Disconnect network", menu_disconnect_network, NULL, NULL },
867 { "10", "Forget network", menu_forget_network, NULL, NULL },
868 { "11", "Get joined mesh network", NULL, run_get_joined_mesh_network, NULL },
869 { "12", "Set softap", menu_softap_option, NULL, NULL },
870 { "13", "Enable softap", NULL, run_enable_softap, NULL },
871 { "14", "Disable softap", NULL, run_disable_softap, NULL },
872 { "15", "Get connected mesh peers", NULL, run_get_connected_peers, NULL },
873 { "16", "Set gate", menu_gate_option, NULL, NULL },
874 { "17", "Unset gate", NULL, run_unset_gate, NULL },
875 { "18", "Get mesh station information", NULL, run_get_station_information, NULL },
876 { "19", "Get mesh path information", NULL, run_get_mpath_information, NULL },