Add internal APIs for mesh path
[platform/core/api/wifi-mesh.git] / test / wifi-mesh-network.c
1
2 /*
3  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/time.h>
23 #include <unistd.h>
24 #include <glib.h>
25 #include <gio/gio.h>
26
27 #include "menu.h"
28 #include "common.h"
29
30 extern wifi_mesh_h mesh;
31
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";
35
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";
43
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] = "";
48
49 static char network_idx[MENU_DATA_SIZE + 1] = "1";
50
51 /* Found Mesh Network */
52 static int g_scan_net_idx = 0;
53 GList *g_found_network_list = NULL;
54
55 static void found_mesh_network_cb(wifi_mesh_network_h network, void* user_data)
56 {
57         int ret;
58         wifi_mesh_network_h net = NULL;
59         char *meshid = NULL;
60         char *bssid = NULL;
61         int rssi;
62         int data_rate;
63         wifi_mesh_security_type_e security;
64         int channel;
65
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);
69                 return;
70         }
71
72         g_found_network_list = g_list_append(g_found_network_list, net);
73
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");
83
84         g_scan_net_idx++;
85
86         if (meshid) free(meshid);
87         if (bssid) free(bssid);
88 }
89
90 static void connected_peer_cb(wifi_mesh_peer_h peer, void* user_data)
91 {
92         char *address = NULL;
93
94         wifi_mesh_peer_get_address(peer, &address);
95         msgb("  Peer Address [%s]", address);
96
97         if (address)
98                 free(address);
99 }
100
101 static void found_station_cb(wifi_mesh_station_info_h station, void* user_data)
102 {
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 */
138
139         msg("Station Information Received: %p", station);
140
141         if (NULL == station)
142                 return;
143
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);
246
247 }
248
249 static void found_mpath_cb(wifi_mesh_mpath_info_h mpath, void* user_data)
250 {
251         int ret = WIFI_MESH_ERROR_NONE;
252
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 */
263
264         msg("Station Information Received: %p", mpath);
265
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)
277                 msg("sn = %d", sn);
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);
296 }
297
298 #if 0
299 static int run_show_found_network(MManager *mm, struct menu_data *menu)
300 {
301         int i = 1; /* Displays from 1 */
302         char *_meshid = NULL;
303         int _channel = 1;
304         wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
305
306         GList *iter = NULL;
307
308         if (NULL == g_found_network_list) {
309                 msgp("There is not any scan result.. do scan first");
310                 return RET_FAILURE;
311         }
312
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");
322
323                 if (_meshid) free(_meshid);
324
325                 iter = g_list_next(iter);
326         }
327
328         return RET_SUCCESS;
329 }
330 #endif
331
332 static int run_wifi_mesh_scan(MManager *mm, struct menu_data *menu)
333 {
334         int ret;
335         msg("Scan");
336
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);
340                 return RET_FAILURE;
341         }
342         msg(" - wifi_mesh_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
343
344         return RET_SUCCESS;
345 }
346
347 static int run_get_found_mesh_network(MManager *mm, struct menu_data *menu)
348 {
349         int ret;
350         msg("Get Found Mesh Network");
351
352         /* Clear previous found network list */
353         g_scan_net_idx = 1;
354         if (g_found_network_list)
355                 g_list_free_full(g_found_network_list, (void *)wifi_mesh_network_destroy);
356
357         g_found_network_list = NULL;
358
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);
363                 return RET_FAILURE;
364         }
365         msg(" - wifi_mesh_foreach_found_network() ret: [0x%X] [%s]",
366                         ret, wifi_mesh_error_to_string(ret));
367
368         return RET_SUCCESS;
369 }
370
371 static int run_wifi_mesh_specific_scan(MManager *mm, struct menu_data *menu)
372 {
373         int ret;
374         int channel = 1;
375
376         msg("Specific scan");
377
378         if (strlen(mesh_channel))
379                 channel = (unsigned short)strtol(mesh_channel, NULL, 10);
380
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);
385                 return RET_FAILURE;
386         }
387         msg(" - wifi_mesh_specific_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
388
389         return RET_SUCCESS;
390 }
391
392 static int run_wifi_mesh_cancel_scan(MManager *mm, struct menu_data *menu)
393 {
394         int ret;
395         msg("Cancel Scan");
396
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);
400                 return RET_FAILURE;
401         }
402         msg(" - wifi_mesh_cancel_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
403
404         return RET_SUCCESS;
405 }
406
407 static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu)
408 {
409         int ret;
410         msg("Enable Mesh");
411
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);
416                 return RET_FAILURE;
417         }
418         msg(" - wifi_mesh_start() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
419
420         return RET_SUCCESS;
421 }
422
423 static int run_wifi_mesh_disable(MManager *mm, struct menu_data *menu)
424 {
425         int ret;
426         msg("Disable Mesh");
427
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);
431                 return RET_FAILURE;
432         }
433         msg(" - wifi_mesh_stop() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
434
435         return RET_SUCCESS;
436 }
437
438 static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu)
439 {
440         int ret;
441         char *_meshid = NULL;
442         char *_bssid = NULL;
443         int _channel = -1;
444         bool joined = false;
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;
448
449         msg("Get Joined Mesh Network Information");
450
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);
455                 return RET_FAILURE;
456         }
457
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);
462                 return RET_FAILURE;
463         }
464
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));
477
478                 if (_meshid) free(_meshid);
479                 if (_bssid) free(_bssid);
480         }
481         msg("");
482         msg(" - wifi_mesh_get_joined_network() ret: [0x%X] [%s]",
483                         ret, wifi_mesh_error_to_string(ret));
484
485         return RET_SUCCESS;
486 }
487
488 static int run_get_connected_peers(MManager *mm, struct menu_data *menu)
489 {
490         int ret;
491         msg("Get Connected Mesh Peers");
492
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);
497                 return RET_FAILURE;
498         }
499         msg(" - wifi_mesh_foreach_connected_peers() ret: [0x%X] [%s]",
500                         ret, wifi_mesh_error_to_string(ret));
501
502         return RET_SUCCESS;
503 }
504
505 static int run_set_gate(MManager *mm, struct menu_data *menu)
506 {
507         int ret;
508         bool _gate_announce = true;
509         int _hwmp_root_mode = 4;
510         bool _stp = true;
511
512         msg("Set Gate Option");
513
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);
518         if (strlen(stp))
519                 _stp = (unsigned short)strtol(stp, NULL, 10);
520
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);
525                 return RET_FAILURE;
526         }
527         msg(" - wifi_mesh_set_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
528
529         return RET_SUCCESS;
530 }
531
532 static int run_unset_gate(MManager *mm, struct menu_data *menu)
533 {
534         int ret;
535         msg("Disable All Gate Option");
536
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);
541                 return RET_FAILURE;
542         }
543         msg(" - wifi_mesh_unset_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
544
545         return RET_SUCCESS;
546 }
547
548 static int run_set_softap(MManager *mm, struct menu_data *menu)
549 {
550         int ret;
551         int _channel = 1;
552         int _visibility = 1;
553         int _max_stations = 10;
554         int _security = 2;
555         msg("Set SoftAp Option");
556
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;
562         }
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);
567
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);
573                 return RET_FAILURE;
574         }
575         msg(" - wifi_mesh_set_softap() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
576
577         return RET_SUCCESS;
578 }
579
580 static int run_enable_softap(MManager *mm, struct menu_data *menu)
581 {
582         int ret;
583         msg("Enable SoftAp");
584
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);
589                 return RET_FAILURE;
590         }
591         msg(" - wifi_mesh_enable_softap() ret: [0x%X] [%s]",
592                         ret, wifi_mesh_error_to_string(ret));
593
594         return RET_SUCCESS;
595 }
596
597 static int run_disable_softap(MManager *mm, struct menu_data *menu)
598 {
599         int ret;
600         msg("Disable SoftAp");
601
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);
606                 return RET_FAILURE;
607         }
608         msg(" - wifi_mesh_disable_softap() ret: [0x%X] [%s]",
609                         ret, wifi_mesh_error_to_string(ret));
610
611         return RET_SUCCESS;
612 }
613
614 static int run_create_network(MManager *mm, struct menu_data *menu)
615 {
616         int ret;
617         int _mesh_channel = 1;
618         wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
619         wifi_mesh_network_h net = NULL;
620
621         msg("Create a new Mesh Network");
622
623         if (strlen(mesh_channel))
624                 _mesh_channel = (unsigned short)strtol(mesh_channel, NULL, 10);
625
626         if (strlen(mesh_security)) {
627                 ret = (unsigned short)strtol(mesh_security, NULL, 10);
628                 security = ((1 == ret) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE);
629         }
630
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);
638                 return RET_FAILURE;
639         }
640         msg(" - wifi_mesh_create_network() ret: [0x%X] [%s]",
641                         ret, wifi_mesh_error_to_string(ret));
642
643         return RET_SUCCESS;
644 }
645
646 static int run_connect_network(MManager *mm, struct menu_data *menu)
647 {
648         int ret;
649         int idx = 1;
650         wifi_mesh_network_h net = NULL;
651         wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
652         msg("Connect to Mesh Network");
653
654         if (strlen(network_idx)) {
655                 idx = (unsigned short)strtol(network_idx, NULL, 10);
656                 if (0 >= idx) {
657                         msgp("Invalid index. set to 1");
658                         idx = 1;
659                 }
660         }
661
662         if (g_found_network_list) {
663                 net = g_list_nth_data(g_found_network_list, idx - 1);
664                 if (NULL == net) {
665                         msgr("Failed to g_hash_table_find");
666                         return RET_FAILURE;
667                 }
668         }
669
670         /* Set passphrase */
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 !");
677                 } else {
678                         msgr("If security enabled, passphrase should be set !");
679                         return RET_FAILURE;
680                 }
681         }
682
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);
687                 return RET_FAILURE;
688         }
689         msg(" - wifi_mesh_connect_network() ret: [0x%X] [%s]",
690                         ret, wifi_mesh_error_to_string(ret));
691
692         return RET_SUCCESS;
693 }
694
695 static int run_disconnect_network(MManager *mm, struct menu_data *menu)
696 {
697         int ret;
698         int idx = 1;
699         wifi_mesh_network_h net = NULL;
700         msg("Disconnect with Mesh Network");
701
702         if (strlen(network_idx)) {
703                 idx = (unsigned short)strtol(network_idx, NULL, 10);
704                 if (0 >= idx) {
705                         msgp("Invalid index. set to 1");
706                         idx = 1;
707                 }
708         }
709
710         if (g_found_network_list) {
711                 net = g_list_nth_data(g_found_network_list, idx - 1);
712                 if (NULL == net) {
713                         msgr("Failed to g_hash_table_find");
714                         return RET_FAILURE;
715                 }
716         }
717
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);
722                 return RET_FAILURE;
723         }
724         msg(" - wifi_mesh_disconnect_network() ret: [0x%X] [%s]",
725                         ret, wifi_mesh_error_to_string(ret));
726
727         return RET_SUCCESS;
728 }
729
730 static int run_forget_network(MManager *mm, struct menu_data *menu)
731 {
732         int ret;
733         int idx = 1;
734         wifi_mesh_network_h net = NULL;
735         msg("Forget Mesh Network");
736
737         if (strlen(network_idx)) {
738                 idx = (unsigned short)strtol(network_idx, NULL, 10);
739                 if (0 >= idx) {
740                         msgp("Invalid index. set to 1");
741                         idx = 1;
742                 }
743         }
744
745         if (g_found_network_list) {
746                 net = g_list_nth_data(g_found_network_list, idx - 1);
747                 if (NULL == net) {
748                         msgr("Failed to g_hash_table_find");
749                         return RET_FAILURE;
750                 }
751         }
752
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);
757                 return RET_FAILURE;
758         }
759         msg(" - wifi_mesh_forget_network() ret: [0x%X] [%s]",
760                         ret, wifi_mesh_error_to_string(ret));
761
762         return RET_SUCCESS;
763 }
764
765 static int run_get_station_information(MManager *mm, struct menu_data *menu)
766 {
767         int ret;
768         msg("Get Mesh Station Information");
769
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);
774                 return RET_FAILURE;
775         }
776         msg(" - wifi_mesh_get_stations_info() ret: [0x%X] [%s]",
777                         ret, wifi_mesh_error_to_string(ret));
778
779         return RET_SUCCESS;
780 }
781
782 static int run_get_mpath_information(MManager *mm, struct menu_data *menu)
783 {
784         int ret;
785         msg("Get Mesh Path Information");
786
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);
791                 return RET_FAILURE;
792         }
793         msg(" - wifi_mesh_get_mpath_info() ret: [0x%X] [%s]",
794                         ret, wifi_mesh_error_to_string(ret));
795
796         return RET_SUCCESS;
797 }
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 },
802         { NULL, NULL, },
803 };
804
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 },
810         { NULL, NULL, },
811 };
812
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 },
822         { NULL, NULL, },
823 };
824
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 },
831         { NULL, NULL, },
832 };
833
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 },
839         { NULL, NULL, },
840 };
841
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 },
846         { NULL, NULL, },
847 };
848
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 },
853         { NULL, NULL, },
854 };
855
856
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 },
877         { NULL, NULL, },
878 };