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 const char *mesh_plink_state_to_string(guchar plink)
125 static const char *power_mode_to_string(guint pm)
128 case 1: /* NL80211_MESH_POWER_ACTIVE */
130 case 2: /* NL80211_MESH_POWER_LIGHT_SLEEP */
131 return "LIGHT SLEEP";
132 case 3: /* NL80211_MESH_POWER_DEEP_SLEEP */
139 static void found_station_cb(wifi_mesh_station_info_h station, void* user_data)
141 int ret = WIFI_MESH_ERROR_NONE;
142 gchar *bssid = NULL; /* station bssid ex) 7c:dd:90:62:37:cf (on mesh0) */
143 guint inactive_time; /**< inactive time ex) 1685 ms */
144 guint64 rx_bytes; /**< rx bytes ex) 34174 */
145 guint rx_packets; /**< rx packet ex) 1181 */
146 guint64 tx_bytes; /**< tx bytes ex) 6877 */
147 guint tx_packets; /**< tx packets ex) 76 */
148 guint tx_retries; /**< tx retries ex) 0 */
149 guint tx_failed; /**< tx failed ex) 0 */
150 guint beacon_loss; /**< beacon loss count ex) 0 */
151 guint64 beacon_rx; /**< beacon rx ex) 0 */
152 guint64 rx_drop_misc; /**< rx drop misc ex) 0 */
153 gint signal; /**< Signal ex) -64 dBm */
154 gint signal_avg; /**< Average Signal ex) -63 dBm */
155 guint tx_bitrate; /**< tx bitrate ex) 54.0 MBit/s => 540 */
156 guint rx_bitrate; /**< rx bitrate ex) 5.5 MBit/s => 55 */
157 gushort mesh_llid; /**< mesh_llid ex) 51731 */
158 gushort mesh_plid; /**< mesh plid ex) 35432 */
159 guchar mesh_plink; /**< mesh plink ex) ESTAB */
160 guint local_ps_mode; /**< mesh local power save mode ex) ACTIVE */
161 guint peer_ps_mode; /**< mesh peer power save mode ex) ACTIVE */
162 guint non_peer_ps_mode; /**< mesh non-peer power save mode ex) ACTIVE */
163 gboolean authorized; /**< authorized ex) yes */
164 gboolean authenticated; /**< authenticated ex) yes */
165 gboolean associated; /**< associated ex) yes */
166 gboolean preamble; /**< preamble ex) long */
167 gboolean wmm_wme; /**< WMM/WME supported ex) yes */
168 gboolean mfp; /**< MFP ex) no */
169 gboolean tdls_peer; /**< TDLS peer ex) no */
170 guchar dtim_period; /**< DTIM period ex) 0 */
171 gushort beacon_interval; /**< beacon interval ex) 1000 */
172 gboolean cts_protection; /**< CTS protection */
173 gboolean short_preamble; /**< short preamble */
174 gboolean short_slot_time; /**< short slot time supported ex) yes */
175 guint connected_time; /**< connected time : ex) 256 seconds */
177 msgp("[%d] Station Information Received", g_idx++);
182 ret = wifi_mesh_get_sta_bssid(station, &bssid);
183 if (WIFI_MESH_ERROR_NONE == ret)
184 msg("bssid = %s", bssid);
185 ret = wifi_mesh_get_sta_inactive_time(station, &inactive_time);
186 if (WIFI_MESH_ERROR_NONE == ret)
187 msg("inactive_time = %d ms", inactive_time);
188 ret = wifi_mesh_get_sta_rx_bytes(station, &rx_bytes);
189 if (WIFI_MESH_ERROR_NONE == ret)
190 msg("rx_bytes = %"G_GUINT64_FORMAT, rx_bytes);
191 ret = wifi_mesh_get_sta_rx_packets(station, &rx_packets);
192 if (WIFI_MESH_ERROR_NONE == ret)
193 msg("rx_packets = %d", rx_packets);
194 ret = wifi_mesh_get_sta_tx_bytes(station, &tx_bytes);
195 if (WIFI_MESH_ERROR_NONE == ret)
196 msg("tx_bytes = %"G_GUINT64_FORMAT, tx_bytes);
197 ret = wifi_mesh_get_sta_tx_packets(station, &tx_packets);
198 if (WIFI_MESH_ERROR_NONE == ret)
199 msg("tx_packets = %d", tx_packets);
200 ret = wifi_mesh_get_sta_tx_retries(station, &tx_retries);
201 if (WIFI_MESH_ERROR_NONE == ret)
202 msg("tx_retries = %d", tx_retries);
203 ret = wifi_mesh_get_sta_tx_failed(station, &tx_failed);
204 if (WIFI_MESH_ERROR_NONE == ret)
205 msg("tx_failed = %d", tx_failed);
206 ret = wifi_mesh_get_sta_beacon_loss(station, &beacon_loss);
207 if (WIFI_MESH_ERROR_NONE == ret)
208 msg("beacon_loss = %d", beacon_loss);
209 ret = wifi_mesh_get_sta_beacon_rx(station, &beacon_rx);
210 if (WIFI_MESH_ERROR_NONE == ret)
211 msg("beacon_rx = %"G_GUINT64_FORMAT, beacon_rx);
212 ret = wifi_mesh_get_sta_rx_drop_misc(station, &rx_drop_misc);
213 if (WIFI_MESH_ERROR_NONE == ret)
214 msg("rx_drop_misc = %"G_GUINT64_FORMAT, rx_drop_misc);
215 ret = wifi_mesh_get_sta_signal(station, &signal);
216 if (WIFI_MESH_ERROR_NONE == ret)
217 msg("signal = %d dBm", signal);
218 ret = wifi_mesh_get_sta_signal_avg(station, &signal_avg);
219 if (WIFI_MESH_ERROR_NONE == ret)
220 msg("signal_avg = %d dBm", signal_avg);
221 ret = wifi_mesh_get_sta_tx_bitrate(station, &tx_bitrate);
222 if (WIFI_MESH_ERROR_NONE == ret)
223 msg("tx_bitrate = %d.%d MBit/s", tx_bitrate / 10, tx_bitrate % 10);
224 ret = wifi_mesh_get_sta_rx_bitrate(station, &rx_bitrate);
225 if (WIFI_MESH_ERROR_NONE == ret)
226 msg("rx_bitrate = %d.%d MBit/s", rx_bitrate / 10, rx_bitrate % 10);
227 ret = wifi_mesh_get_sta_mesh_llid(station, &mesh_llid);
228 if (WIFI_MESH_ERROR_NONE == ret)
229 msg("mesh_llid = %d", mesh_llid);
230 ret = wifi_mesh_get_sta_mesh_plid(station, &mesh_plid);
231 if (WIFI_MESH_ERROR_NONE == ret)
232 msg("mesh_plid = %d", mesh_plid);
233 ret = wifi_mesh_get_sta_mesh_plink(station, &mesh_plink);
234 if (WIFI_MESH_ERROR_NONE == ret)
235 msg("mesh_plink = %s", mesh_plink_state_to_string(mesh_plink));
236 ret = wifi_mesh_get_sta_local_ps_mode(station, &local_ps_mode);
237 if (WIFI_MESH_ERROR_NONE == ret)
238 msg("local_ps_mode = %s", power_mode_to_string(local_ps_mode));
239 ret = wifi_mesh_get_sta_peer_ps_mode(station, &peer_ps_mode);
240 if (WIFI_MESH_ERROR_NONE == ret)
241 msg("peer_ps_mode = %s", power_mode_to_string(peer_ps_mode));
242 ret = wifi_mesh_get_sta_non_peer_ps_mode(station, &non_peer_ps_mode);
243 if (WIFI_MESH_ERROR_NONE == ret)
244 msg("non_peer_ps_mode = %s", power_mode_to_string(non_peer_ps_mode));
245 ret = wifi_mesh_get_sta_authorized(station, &authorized);
246 if (WIFI_MESH_ERROR_NONE == ret)
247 msg("authorized = %s", authorized ? "yes" : "no");
248 ret = wifi_mesh_get_sta_authenticated(station, &authenticated);
249 if (WIFI_MESH_ERROR_NONE == ret)
250 msg("authenticated = %s", authenticated ? "yes" : "no");
251 ret = wifi_mesh_get_sta_associated(station, &associated);
252 if (WIFI_MESH_ERROR_NONE == ret)
253 msg("associated = %s", associated ? "yes" : "no");
254 ret = wifi_mesh_get_sta_preamble(station, &preamble);
255 if (WIFI_MESH_ERROR_NONE == ret)
256 msg("preamble = %s", preamble ? "short" : "long");
257 ret = wifi_mesh_get_sta_wmm_wme(station, &wmm_wme);
258 if (WIFI_MESH_ERROR_NONE == ret)
259 msg("wmm_wme = %s", wmm_wme ? "yes" : "no");
260 ret = wifi_mesh_get_sta_mfp(station, &mfp);
261 if (WIFI_MESH_ERROR_NONE == ret)
262 msg("mfp = %s", mfp ? "yes" : "no");
263 ret = wifi_mesh_get_sta_tdls_peer(station, &tdls_peer);
264 if (WIFI_MESH_ERROR_NONE == ret)
265 msg("tdls_peer = %s", tdls_peer ? "yes" : "no");
266 ret = wifi_mesh_get_sta_dtim_period(station, &dtim_period);
267 if (WIFI_MESH_ERROR_NONE == ret)
268 msg("dtim_period = %d", dtim_period);
269 ret = wifi_mesh_get_sta_beacon_interval(station, &beacon_interval);
270 if (WIFI_MESH_ERROR_NONE == ret)
271 msg("beacon_interval = %d", beacon_interval);
272 ret = wifi_mesh_get_sta_cts_protection(station, &cts_protection);
273 if (WIFI_MESH_ERROR_NONE == ret)
274 msg("cts_protection = %d", cts_protection);
275 ret = wifi_mesh_get_sta_short_preamble(station, &short_preamble);
276 if (WIFI_MESH_ERROR_NONE == ret)
277 msg("short_preamble = %d", short_preamble);
278 ret = wifi_mesh_get_sta_short_slot_time(station, &short_slot_time);
279 if (WIFI_MESH_ERROR_NONE == ret)
280 msg("short_slot_time = %s", short_slot_time ? "yes" : "no");
281 ret = wifi_mesh_get_sta_connected_time(station, &connected_time);
282 if (WIFI_MESH_ERROR_NONE == ret)
283 msg("connected_time = %d seconds", connected_time);
287 static void found_mpath_cb(wifi_mesh_mpath_info_h mpath, void* user_data)
289 int ret = WIFI_MESH_ERROR_NONE;
291 gchar *dest_addr = NULL; /**< destination address */
292 gchar *next_hop = NULL; /**< next hop address */
293 gchar *iface = NULL; /**< network interface for mesh */
294 guint sn; /**< sequence number */
295 guint metric; /**< metric */
296 guint qlen; /**< driver queue length */
297 guint exptime; /**< expire time */
298 guint discovery_timeout; /**< Discovery timeout */
299 guchar discovery_retries; /**< Discovery retries */
300 guchar flags; /**< Flags */
302 msgp("[%d] routing Information Received", g_idx++);
304 ret = wifi_mesh_get_mpath_dest_addr(mpath, &dest_addr);
305 if (WIFI_MESH_ERROR_NONE == ret)
306 msg("dest_addr = %s", dest_addr);
307 ret = wifi_mesh_get_mpath_next_hop(mpath, &next_hop);
308 if (WIFI_MESH_ERROR_NONE == ret)
309 msg("next_hop = %s", next_hop);
310 ret = wifi_mesh_get_mpath_iface(mpath, &iface);
311 if (WIFI_MESH_ERROR_NONE == ret)
312 msg("iface = %s", iface);
313 ret = wifi_mesh_get_mpath_sn(mpath, &sn);
314 if (WIFI_MESH_ERROR_NONE == ret)
316 ret = wifi_mesh_get_mpath_metric(mpath, &metric);
317 if (WIFI_MESH_ERROR_NONE == ret)
318 msg("metric = %d", metric);
319 ret = wifi_mesh_get_mpath_qlen(mpath, &qlen);
320 if (WIFI_MESH_ERROR_NONE == ret)
321 msg("qlen = %d", qlen);
322 ret = wifi_mesh_get_mpath_exptime(mpath, &exptime);
323 if (WIFI_MESH_ERROR_NONE == ret)
324 msg("exptime = %d", exptime);
325 ret = wifi_mesh_get_mpath_disc_timeout(mpath, &discovery_timeout);
326 if (WIFI_MESH_ERROR_NONE == ret)
327 msg("discovery_timeout = %d", discovery_timeout);
328 ret = wifi_mesh_get_mpath_disc_retries(mpath, &discovery_retries);
329 if (WIFI_MESH_ERROR_NONE == ret)
330 msg("discovery_retries = %d", discovery_retries);
331 ret = wifi_mesh_get_mpath_flags(mpath, &flags);
332 if (WIFI_MESH_ERROR_NONE == ret)
333 msg("flags = %d", flags);
338 static int run_show_found_network(MManager *mm, struct menu_data *menu)
340 int i = 1; /* Displays from 1 */
341 char *_meshid = NULL;
343 wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
347 if (NULL == g_found_network_list) {
348 msgp("There is not any scan result.. do scan first");
352 msg("Scan Results : ");
353 iter = g_found_network_list;
354 while (iter != NULL) {
355 wifi_mesh_network_h _net = iter->data;
356 wifi_mesh_network_get_meshid(_net, &_meshid);
357 wifi_mesh_network_get_channel(_net, &_channel);
358 wifi_mesh_network_get_security(_net, &_security);
359 msgb(" [%02d] Mesh ID[%-10s] Channel[%d] Security[%4s]", i++,
360 _meshid, _channel, (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE");
362 if (_meshid) free(_meshid);
364 iter = g_list_next(iter);
371 static int run_wifi_mesh_scan(MManager *mm, struct menu_data *menu)
376 ret = wifi_mesh_scan(mesh);
377 if (WIFI_MESH_ERROR_NONE != ret) {
378 msgr("Failed to scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
381 msg(" - wifi_mesh_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
386 static int run_get_found_mesh_network(MManager *mm, struct menu_data *menu)
389 msg("Get Found Mesh Network");
391 /* Clear previous found network list */
393 if (g_found_network_list)
394 g_list_free_full(g_found_network_list, (void *)wifi_mesh_network_destroy);
396 g_found_network_list = NULL;
398 ret = wifi_mesh_foreach_found_network(mesh, found_mesh_network_cb, NULL);
399 if (WIFI_MESH_ERROR_NONE != ret) {
400 msgr("Failed to wifi_mesh_foreach_found_network: [%s(0x%X)]",
401 wifi_mesh_error_to_string(ret), ret);
404 msg(" - wifi_mesh_foreach_found_network() ret: [0x%X] [%s]",
405 ret, wifi_mesh_error_to_string(ret));
410 static int run_wifi_mesh_specific_scan(MManager *mm, struct menu_data *menu)
415 msg("Specific scan");
417 if (strlen(mesh_channel))
418 channel = (unsigned short)strtol(mesh_channel, NULL, 10);
420 ret = wifi_mesh_specific_scan(mesh, meshid, channel);
421 if (WIFI_MESH_ERROR_NONE != ret) {
422 msgr("Failed to specific scan: [%s(0x%X)]",
423 wifi_mesh_error_to_string(ret), ret);
426 msg(" - wifi_mesh_specific_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
431 static int run_wifi_mesh_cancel_scan(MManager *mm, struct menu_data *menu)
436 ret = wifi_mesh_cancel_scan(mesh);
437 if (WIFI_MESH_ERROR_NONE != ret) {
438 msgr("Failed to cancel scan: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
441 msg(" - wifi_mesh_cancel_scan() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
446 static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu)
451 ret = wifi_mesh_is_started(mesh, &is_started);
452 if (WIFI_MESH_ERROR_NONE != ret) {
453 msgr("Failed to check mesh started: [%s(0x%X)]",
454 wifi_mesh_error_to_string(ret), ret);
458 if (is_started == true) {
459 msg("Mesh is already enabled");
465 ret = wifi_mesh_start(mesh);
466 if (WIFI_MESH_ERROR_NONE != ret) {
467 msgr("Failed to enable mesh network: [%s(0x%X)]",
468 wifi_mesh_error_to_string(ret), ret);
471 msg(" - wifi_mesh_start() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
476 static int run_wifi_mesh_disable(MManager *mm, struct menu_data *menu)
481 ret = wifi_mesh_stop(mesh);
482 if (WIFI_MESH_ERROR_NONE != ret) {
483 msgr("Failed to disable mesh network: [%s(0x%X)]", wifi_mesh_error_to_string(ret), ret);
486 msg(" - wifi_mesh_stop() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
491 static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu)
494 char *_meshid = NULL;
498 wifi_mesh_connection_state_e _state = WIFI_MESH_CONNECTION_STATE_DISCONNECTED;
499 wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
500 wifi_mesh_ip_config_type_e _ipv4_type = WIFI_MESH_IP_CONFIG_TYPE_UNKNOWN;
501 char *_ipv4_address = NULL;
502 char *_ipv4_netmask = NULL;
503 wifi_mesh_network_h network = NULL;
505 msg("Get Joined Mesh Network Information");
507 ret = wifi_mesh_is_joined(mesh, &joined);
508 if (WIFI_MESH_ERROR_NONE != ret) {
509 msgr("Failed to check network join status: [%s(0x%X)]",
510 wifi_mesh_error_to_string(ret), ret);
514 ret = wifi_mesh_get_joined_network(mesh, &network);
515 if (WIFI_MESH_ERROR_NONE != ret) {
516 msgr("Failed to get joined mesh network: [%s(0x%X)]",
517 wifi_mesh_error_to_string(ret), ret);
521 if (NULL != network) {
522 wifi_mesh_network_get_meshid(network, &_meshid);
523 msgb(" Mesh ID = %s", _meshid);
524 wifi_mesh_network_get_bssid(network, &_bssid);
525 msgb(" BSSID = %s", _bssid);
526 wifi_mesh_network_get_channel(network, &_channel);
527 msgb(" Channel = %d", _channel);
528 wifi_mesh_network_get_security(network, &_security);
529 msgb(" Security = %s",
530 (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE");
531 wifi_mesh_network_get_connection_state(network, &_state);
532 msgb(" State = %s", wifi_mesh_connection_event_to_string(_state));
533 wifi_mesh_network_get_ip_config_type(network,
534 WIFI_MESH_ADDRESS_FAMILY_IPV4, &_ipv4_type);
535 msgb(" IPv4 Config Type = %d", _ipv4_type);
536 wifi_mesh_network_get_ip_address(network, WIFI_MESH_ADDRESS_FAMILY_IPV4,
538 msgb(" IPv4 Address = %s", _ipv4_address);
539 wifi_mesh_network_get_subnet_mask(network,
540 WIFI_MESH_ADDRESS_FAMILY_IPV4, &_ipv4_netmask);
541 msgb(" IPv4 Subnet Mask = %s", _ipv4_netmask);
543 if (_meshid) free(_meshid);
544 if (_bssid) free(_bssid);
545 if (_ipv4_address) free(_ipv4_address);
546 if (_ipv4_netmask) free(_ipv4_netmask);
549 msg(" - wifi_mesh_get_joined_network() ret: [0x%X] [%s]",
550 ret, wifi_mesh_error_to_string(ret));
555 static int run_get_connected_peers(MManager *mm, struct menu_data *menu)
558 msg("Get Connected Mesh Peers");
560 ret = wifi_mesh_foreach_connected_peers(mesh, connected_peer_cb, NULL);
561 if (WIFI_MESH_ERROR_NONE != ret) {
562 msgr("Failed to wifi_mesh_foreach_connected_peers: [%s(0x%X)]",
563 wifi_mesh_error_to_string(ret), ret);
566 msg(" - wifi_mesh_foreach_connected_peers() ret: [0x%X] [%s]",
567 ret, wifi_mesh_error_to_string(ret));
572 static int run_set_gate(MManager *mm, struct menu_data *menu)
575 bool _gate_announce = true;
576 int _hwmp_root_mode = 4;
579 msg("Set Gate Option");
581 if (strlen(gate_announce))
582 _gate_announce = (unsigned short)strtol(gate_announce, NULL, 16);
583 if (strlen(hwmp_root_mode))
584 _hwmp_root_mode = (unsigned short)strtol(hwmp_root_mode, NULL, 10);
586 _stp = (unsigned short)strtol(stp, NULL, 10);
588 ret = wifi_mesh_set_gate(mesh, _gate_announce, _hwmp_root_mode, _stp);
589 if (WIFI_MESH_ERROR_NONE != ret) {
590 msgr("Failed to set gate options: [%s(0x%X)]",
591 wifi_mesh_error_to_string(ret), ret);
594 msg(" - wifi_mesh_set_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
599 static int run_unset_gate(MManager *mm, struct menu_data *menu)
602 msg("Disable All Gate Option");
604 ret = wifi_mesh_unset_gate(mesh);
605 if (WIFI_MESH_ERROR_NONE != ret) {
606 msgr("Failed to unset gate option: [%s(0x%X)]",
607 wifi_mesh_error_to_string(ret), ret);
610 msg(" - wifi_mesh_unset_gate() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
615 static int run_set_softap(MManager *mm, struct menu_data *menu)
620 int _max_stations = 10;
622 msg("Set SoftAp Option");
624 if (strlen(softap_channel))
625 _channel = (unsigned short)strtol(softap_channel, NULL, 10);
626 if (strlen(visibility)) {
627 _visibility = (unsigned short)strtol(visibility, NULL, 10);
628 if (1 != _visibility) _visibility = 0;
630 if (strlen(max_stations))
631 _max_stations = (unsigned short)strtol(max_stations, NULL, 10);
632 if (strlen(security))
633 _security = (unsigned short)strtol(security, NULL, 10);
635 ret = wifi_mesh_set_softap(mesh, ssid, passphrase,
636 _channel, _visibility, _max_stations, _security);
637 if (WIFI_MESH_ERROR_NONE != ret) {
638 msgr("Failed to set softap options: [%s(0x%X)]",
639 wifi_mesh_error_to_string(ret), ret);
642 msg(" - wifi_mesh_set_softap() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
644 msg("Get SoftAp Option");
645 char *g_ssid, *g_key;
646 int g_channel, g_max_stations, g_security;
648 ret = wifi_mesh_get_softap(mesh, &g_ssid, &g_channel, &g_visibility,
649 &g_max_stations, &g_security, &g_key);
650 if (WIFI_MESH_ERROR_NONE != ret) {
651 msgr("Failed to get softap options: [%s(0x%X)]",
652 wifi_mesh_error_to_string(ret), ret);
656 msg("SSID: %s", g_ssid);
657 msg("Channel: %d", g_channel);
658 msg("Visibility: %d", g_visibility);
659 msg("Max Stations: %d", g_max_stations);
660 msg("Security: %d", g_security);
661 msg("Key: %s", g_security ? g_key : "NULL");
669 static int run_enable_softap(MManager *mm, struct menu_data *menu)
672 msg("Enable SoftAp");
674 ret = wifi_mesh_enable_softap(mesh);
675 if (WIFI_MESH_ERROR_NONE != ret) {
676 msgr("Failed to enable soft ap: [%s(0x%X)]",
677 wifi_mesh_error_to_string(ret), ret);
680 msg(" - wifi_mesh_enable_softap() ret: [0x%X] [%s]",
681 ret, wifi_mesh_error_to_string(ret));
686 static int run_disable_softap(MManager *mm, struct menu_data *menu)
690 msg("Check SoftAp status");
692 ret = wifi_mesh_is_softap_started(mesh, &status);
693 if (WIFI_MESH_ERROR_NONE != ret) {
694 msgr("Failed to check soft ap status: [%s(0x%X)]",
695 wifi_mesh_error_to_string(ret), ret);
699 if (status == false) {
700 msg("SoftAP is already disabled");
704 msg("Disable SoftAp");
706 ret = wifi_mesh_disable_softap(mesh);
707 if (WIFI_MESH_ERROR_NONE != ret) {
708 msgr("Failed to disable soft ap: [%s(0x%X)]",
709 wifi_mesh_error_to_string(ret), ret);
712 msg(" - wifi_mesh_disable_softap() ret: [0x%X] [%s]",
713 ret, wifi_mesh_error_to_string(ret));
718 static int run_create_network(MManager *mm, struct menu_data *menu)
721 int _mesh_channel = 1;
722 wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
723 wifi_mesh_network_h net = NULL;
725 msg("Create a new Mesh Network");
727 if (strlen(mesh_channel))
728 _mesh_channel = (unsigned short)strtol(mesh_channel, NULL, 10);
730 if (strlen(mesh_security)) {
731 ret = (unsigned short)strtol(mesh_security, NULL, 10);
732 security = ((1 == ret) ? MESH_SECURITY_SAE : MESH_SECURITY_NONE);
735 wifi_mesh_network_new_with(&net, meshid, NULL, _mesh_channel, 0,
736 security, security == MESH_SECURITY_SAE ? mesh_passphrase : NULL);
737 ret = wifi_mesh_create_network(mesh, net);
738 wifi_mesh_network_destroy(net);
739 if (WIFI_MESH_ERROR_NONE != ret) {
740 msgr("Failed to wifi_mesh_create_network: [%s(0x%X)]",
741 wifi_mesh_error_to_string(ret), ret);
744 msg(" - wifi_mesh_create_network() ret: [0x%X] [%s]",
745 ret, wifi_mesh_error_to_string(ret));
750 static int run_connect_network(MManager *mm, struct menu_data *menu)
754 wifi_mesh_network_h net = NULL;
755 wifi_mesh_security_type_e security = MESH_SECURITY_NONE;
756 msg("Connect to Mesh Network");
758 if (strlen(network_idx)) {
759 idx = (unsigned short)strtol(network_idx, NULL, 10);
761 msgp("Invalid index. set to 1");
766 if (g_found_network_list) {
767 net = g_list_nth_data(g_found_network_list, idx - 1);
769 msgr("Failed to g_hash_table_find");
775 wifi_mesh_network_get_security(net, &security);
776 if (MESH_SECURITY_NONE != security) {
777 if (strlen(mesh_passphrase)) {
778 ret = wifi_mesh_network_set_passphrase(net, mesh_passphrase);
779 if (WIFI_MESH_ERROR_NONE != ret)
780 msgr("Failed to set passphrase !");
782 msgr("If security enabled, passphrase should be set !");
787 ret = wifi_mesh_connect_network(mesh, net);
788 if (WIFI_MESH_ERROR_NONE != ret) {
789 msgr("Failed to wifi_mesh_connect_network: [%s(0x%X)]",
790 wifi_mesh_error_to_string(ret), ret);
793 msg(" - wifi_mesh_connect_network() ret: [0x%X] [%s]",
794 ret, wifi_mesh_error_to_string(ret));
799 static int run_disconnect_network(MManager *mm, struct menu_data *menu)
803 wifi_mesh_network_h net = NULL;
804 msg("Disconnect with Mesh Network");
806 if (strlen(network_idx)) {
807 idx = (unsigned short)strtol(network_idx, NULL, 10);
809 msgp("Invalid index. set to 1");
814 if (g_found_network_list) {
815 net = g_list_nth_data(g_found_network_list, idx - 1);
817 msgr("Failed to g_hash_table_find");
822 ret = wifi_mesh_disconnect_network(mesh, net);
823 if (WIFI_MESH_ERROR_NONE != ret) {
824 msgr("Failed to wifi_mesh_disconnect_network: [%s(0x%X)]",
825 wifi_mesh_error_to_string(ret), ret);
828 msg(" - wifi_mesh_disconnect_network() ret: [0x%X] [%s]",
829 ret, wifi_mesh_error_to_string(ret));
834 static int run_forget_network(MManager *mm, struct menu_data *menu)
838 wifi_mesh_network_h net = NULL;
839 msg("Forget Mesh Network");
841 if (strlen(network_idx)) {
842 idx = (unsigned short)strtol(network_idx, NULL, 10);
844 msgp("Invalid index. set to 1");
849 if (g_found_network_list) {
850 net = g_list_nth_data(g_found_network_list, idx - 1);
852 msgr("Failed to g_hash_table_find");
857 ret = wifi_mesh_forget_network(mesh, net);
858 if (WIFI_MESH_ERROR_NONE != ret) {
859 msgr("Failed to wifi_mesh_forget_network: [%s(0x%X)]",
860 wifi_mesh_error_to_string(ret), ret);
863 msg(" - wifi_mesh_forget_network() ret: [0x%X] [%s]",
864 ret, wifi_mesh_error_to_string(ret));
869 static int run_get_station_information(MManager *mm, struct menu_data *menu)
872 msg("Get Mesh Station Information");
876 ret = wifi_mesh_get_stations_info(mesh, MESH_STATION_TYPE_MESH_POINT,
877 found_station_cb, NULL);
878 if (WIFI_MESH_ERROR_NONE != ret) {
879 msgr("Failed to wifi_mesh_get_stations_info: [%s(0x%X)]",
880 wifi_mesh_error_to_string(ret), ret);
883 msg(" - wifi_mesh_get_stations_info() ret: [0x%X] [%s]",
884 ret, wifi_mesh_error_to_string(ret));
889 static int run_get_mpath_information(MManager *mm, struct menu_data *menu)
892 msg("Get Mesh Path Information");
896 ret = wifi_mesh_get_mpath_info(mesh, found_mpath_cb, NULL);
897 if (WIFI_MESH_ERROR_NONE != ret) {
898 msgr("Failed to wifi_mesh_get_mpath_info: [%s(0x%X)]",
899 wifi_mesh_error_to_string(ret), ret);
902 msg(" - wifi_mesh_get_mpath_info() ret: [0x%X] [%s]",
903 ret, wifi_mesh_error_to_string(ret));
908 static int run_get_meshconf_information(MManager *mm, struct menu_data *menu)
911 wifi_mesh_meshconf_info_h meshconf;
912 gushort retry_timeout; /**< Retry Timeout */
913 guchar hwmp_max_preq_retries; /**< HWMP Max Preq Retries */
914 gushort confirm_timeout; /**< Confirm Timeout */
915 guint path_refresh_time; /**< Path Refresh Time */
916 gushort holding_timeout; /**< Holding Timeout */
917 gushort min_disc_timeout; /**< Min Discovery Timeout */
918 gushort max_peer_links; /**< Max Peer Links */
919 gushort hwmp_preq_min_interval; /**< HWMP PREQ Min Interval */
920 guchar ttl; /**< TTL */
921 guint hwmp_active_path_timeout; /**< HWMP Active Path Timeout */
922 guchar element_ttl; /**< Element TTL */
923 gushort hwmp_rann_interval; /**< HWMP RANN Interval */
924 guchar gate_announcements; /**< Gate Announcements */
925 msg("Get Mesh Conf Information");
929 ret = wifi_mesh_get_meshconf_info(mesh, &meshconf);
930 if (WIFI_MESH_ERROR_NONE != ret) {
931 msgr("Failed to wifi_mesh_get_meshconf_info: [%s(0x%X)]",
932 wifi_mesh_error_to_string(ret), ret);
936 msg("Mesh Configuration Informations:");
938 ret = wifi_mesh_get_meshconf_retry_timeout(meshconf, &retry_timeout);
939 if (WIFI_MESH_ERROR_NONE == ret)
940 msg("retry_timeout = %u", retry_timeout);
941 ret = wifi_mesh_get_meshconf_hwmp_max_preq_retries(meshconf,
942 &hwmp_max_preq_retries);
943 if (WIFI_MESH_ERROR_NONE == ret)
944 msg("hwmp_max_preq_retries = %u", hwmp_max_preq_retries);
945 ret = wifi_mesh_get_meshconf_confirm_timeout(meshconf, &confirm_timeout);
946 if (WIFI_MESH_ERROR_NONE == ret)
947 msg("confirm_timeout = %u", confirm_timeout);
948 ret = wifi_mesh_get_meshconf_path_refresh_time(meshconf,
950 if (WIFI_MESH_ERROR_NONE == ret)
951 msg("path_refresh_time = %u", path_refresh_time);
952 ret = wifi_mesh_get_meshconf_holding_timeout(meshconf, &holding_timeout);
953 if (WIFI_MESH_ERROR_NONE == ret)
954 msg("holding_timeout = %u", holding_timeout);
955 ret = wifi_mesh_get_meshconf_min_disc_timeout(meshconf, &min_disc_timeout);
956 if (WIFI_MESH_ERROR_NONE == ret)
957 msg("min_disc_timeout = %u", min_disc_timeout);
958 ret = wifi_mesh_get_meshconf_max_peer_links(meshconf, &max_peer_links);
959 if (WIFI_MESH_ERROR_NONE == ret)
960 msg("max_peer_links = %u", max_peer_links);
961 ret = wifi_mesh_get_meshconf_hwmp_preq_min_interval(meshconf,
962 &hwmp_preq_min_interval);
963 if (WIFI_MESH_ERROR_NONE == ret)
964 msg("hwmp_preq_min_interval = %u", hwmp_preq_min_interval);
965 ret = wifi_mesh_get_meshconf_ttl(meshconf, &ttl);
966 if (WIFI_MESH_ERROR_NONE == ret)
967 msg("ttl = %u", ttl);
968 ret = wifi_mesh_get_meshconf_hwmp_active_path_timeout(meshconf,
969 &hwmp_active_path_timeout);
970 if (WIFI_MESH_ERROR_NONE == ret)
971 msg("hwmp_active_path_timeout = %u", hwmp_active_path_timeout);
972 ret = wifi_mesh_get_meshconf_element_ttl(meshconf, &element_ttl);
973 if (WIFI_MESH_ERROR_NONE == ret)
974 msg("element_ttl = %u", element_ttl);
975 ret = wifi_mesh_get_meshconf_hwmp_rann_interval(meshconf,
976 &hwmp_rann_interval);
977 if (WIFI_MESH_ERROR_NONE == ret)
978 msg("hwmp_rann_interval = %u", hwmp_rann_interval);
979 ret = wifi_mesh_get_meshconf_gate_announcements(meshconf,
980 &gate_announcements);
981 if (WIFI_MESH_ERROR_NONE == ret)
982 msg("gate_announcements = %u", gate_announcements);
984 ret = wifi_mesh_destroy_meshconf_info(meshconf);
985 if (WIFI_MESH_ERROR_NONE != ret) {
986 msgr("Failed to wifi_mesh_destroy_meshconf_info: [%s(0x%X)]",
987 wifi_mesh_error_to_string(ret), ret);
990 msg("Successfully destroyed meshconf info");
995 static int run_get_softap_station_info(MManager *mm, struct menu_data *menu)
998 msg("Get SoftAP Station Information");
1002 ret = wifi_mesh_get_stations_info(mesh, MESH_STATION_TYPE_SOFTAP,
1003 found_station_cb, NULL);
1004 if (WIFI_MESH_ERROR_NONE != ret) {
1005 msgr("Failed to wifi_mesh_get_stations_info: [%s(0x%X)]",
1006 wifi_mesh_error_to_string(ret), ret);
1009 msg(" - wifi_mesh_get_stations_info() ret: [0x%X] [%s]",
1010 ret, wifi_mesh_error_to_string(ret));
1015 static struct menu_data menu_specific_scan[] = {
1016 { "1", "Mesh ID", NULL, NULL, meshid },
1017 { "2", "Channel", NULL, NULL, mesh_channel },
1018 { "3", "Run", NULL, run_wifi_mesh_specific_scan, NULL },
1022 static struct menu_data menu_gate_option[] = {
1023 { "1", "Gate Announcement", NULL, NULL, gate_announce },
1024 { "2", "HWMP Root Mode", NULL, NULL, hwmp_root_mode },
1025 { "3", "STP", NULL, NULL, stp },
1026 { "4", "Run", NULL, run_set_gate, NULL },
1030 static struct menu_data menu_softap_option[] = {
1031 { "1", "SSID", NULL, NULL, ssid },
1032 { "2", "passphrase", NULL, NULL, passphrase },
1033 { "3", "802.11 mode", NULL, NULL, mode },
1034 { "4", "channel", NULL, NULL, softap_channel },
1035 { "5", "SSID broadcast=1, hidden=0", NULL, NULL, visibility },
1036 { "6", "max. client num", NULL, NULL, max_stations },
1037 { "6", "security (wpa1=1, wpa2=2)", NULL, NULL, security },
1038 { "7", "run", NULL, run_set_softap, NULL },
1042 static struct menu_data menu_create_network[] = {
1043 { "1", "Mesh ID", NULL, NULL, meshid },
1044 { "2", "Channel", NULL, NULL, mesh_channel },
1045 { "3", "Security (0=None,1=SAE)", NULL, NULL, mesh_security },
1046 { "4", "Passphrase", NULL, NULL, mesh_passphrase },
1047 { "5", "Run", NULL, run_create_network, NULL },
1051 static struct menu_data menu_connect_network[] = {
1052 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
1053 { "1", "Index", NULL, NULL, network_idx },
1054 { "2", "Passphrase", NULL, NULL, mesh_passphrase },
1055 { "3", "Run", NULL, run_connect_network, NULL },
1059 static struct menu_data menu_disconnect_network[] = {
1060 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
1061 { "1", "Index", NULL, NULL, network_idx },
1062 { "2", "Run", NULL, run_disconnect_network, NULL },
1066 static struct menu_data menu_forget_network[] = {
1067 { "0", "Show found networks", NULL, run_get_found_mesh_network, NULL },
1068 { "1", "Index", NULL, NULL, network_idx },
1069 { "2", "Run", NULL, run_forget_network, NULL },
1074 struct menu_data menu_mesh_network[] = {
1075 { "1", "Start", NULL, run_wifi_mesh_enable, NULL },
1076 { "2", "Stop", NULL, run_wifi_mesh_disable, NULL },
1077 { "3", "Scan", NULL, run_wifi_mesh_scan, NULL },
1078 { "4", "Specific scan", menu_specific_scan, NULL, NULL },
1079 { "5", "Cancel scan", NULL, run_wifi_mesh_cancel_scan, NULL },
1080 { "6", "Get found mesh network", NULL, run_get_found_mesh_network, NULL },
1081 { "7", "Create network", menu_create_network, NULL, NULL },
1082 { "8", "Connect network", menu_connect_network, NULL, NULL },
1083 { "9", "Disconnect network", menu_disconnect_network, NULL, NULL },
1084 { "10", "Forget network", menu_forget_network, NULL, NULL },
1085 { "11", "Get joined mesh network", NULL, run_get_joined_mesh_network, NULL },
1086 { "12", "Set softap", menu_softap_option, NULL, NULL },
1087 { "13", "Enable softap", NULL, run_enable_softap, NULL },
1088 { "14", "Disable softap", NULL, run_disable_softap, NULL },
1089 { "15", "Get connected mesh peers", NULL, run_get_connected_peers, NULL },
1090 { "16", "Set gate", menu_gate_option, NULL, NULL },
1091 { "17", "Unset gate", NULL, run_unset_gate, NULL },
1092 { "18", "Get mesh station information", NULL, run_get_station_information, NULL },
1093 { "19", "Get mesh path information", NULL, run_get_mpath_information, NULL },
1094 { "20", "Get mesh conf information", NULL, run_get_meshconf_information,
1096 { "21", "Get softap station information", NULL, run_get_softap_station_info,