This shows you the differences between two versions of the page.
sdk:scripts:scan-mobile [2015/05/05 15:04] |
sdk:scripts:scan-mobile [2015/05/05 15:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SDK Script scan-mobile.are ====== | ||
+ | <code c scan-mobile.are> | ||
+ | /* DESC: This script can be used to switch the Mobile LAI according to available networks | ||
+ | * Copyright (C) 2013 NetModule AG, Switzerland | ||
+ | */ | ||
+ | |||
+ | IFC = "Mobile1"; | ||
+ | LAI = ""; | ||
+ | OPERATOR = "MyOperator"; | ||
+ | |||
+ | /* ATTENTION: Scanning for mobile networks will tear down any running WWAN connections */ | ||
+ | nets = nb_scan_networks(IFC); | ||
+ | nr_nets = struct_get(nets, "NETWORK_COUNT"); | ||
+ | |||
+ | if (is_void(nr_nets) || nr_nets < 1) { | ||
+ | nb_syslog("no networks found on %s", IFC); | ||
+ | exit(0); | ||
+ | } | ||
+ | |||
+ | /* lookup mobile networks */ | ||
+ | for (i = 1; i <= nr_nets; i++) { | ||
+ | k = sprintf("NETWORK%d_NAME", i); | ||
+ | net = struct_get(nets, k); | ||
+ | k = sprintf("NETWORK%d_LAI", i); | ||
+ | lai = struct_get(nets, k); | ||
+ | k = sprintf("NETWORK%d_STATUS", i); | ||
+ | status = struct_get(nets, k); | ||
+ | |||
+ | nb_syslog("detected %s network '%s' (lai %s, status %s)", IFC, net, lai, status); | ||
+ | |||
+ | if (net == OPERATOR && strlen(lai) > 0 && status == "available") { | ||
+ | nb_syslog("using LAI %s of '%s'", lai, net); | ||
+ | LAI = lai; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (LAI != "") { | ||
+ | nb_syslog("setting LAI %s on %s", LAI, IFC); | ||
+ | cfg = sprintf("sim.0.lai=%s", LAI); | ||
+ | nb_config_set(cfg); | ||
+ | } else { | ||
+ | nb_syslog("no known networks found on %s", IFC); | ||
+ | } | ||
+ | |||
+ | exit(0); | ||
+ | |||
+ | </code> | ||