2 * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <sys/types.h>
28 #include <osmocore/utils.h>
29 #include <osmocore/gsm48.h>
31 #include <osmocom/bb/common/osmocom_data.h>
32 #include <osmocom/bb/common/networks.h>
33 #include <osmocom/bb/mobile/mncc.h>
34 #include <osmocom/bb/mobile/transaction.h>
35 #include <osmocom/bb/mobile/vty.h>
36 #include <osmocom/bb/mobile/gps.h>
37 #include <osmocom/vty/telnet_interface.h>
39 int mncc_call(struct osmocom_ms *ms, char *number);
40 int mncc_hangup(struct osmocom_ms *ms);
41 int mncc_answer(struct osmocom_ms *ms);
42 int mncc_hold(struct osmocom_ms *ms);
43 int mncc_retrieve(struct osmocom_ms *ms, int number);
45 extern struct llist_head ms_list;
46 extern struct llist_head active_connections;
48 struct cmd_node ms_node = {
54 struct cmd_node testsim_node = {
60 static void print_vty(void *priv, const char *fmt, ...)
63 struct vty *vty = priv;
67 vsnprintf(buffer, sizeof(buffer) - 1, fmt, args);
68 buffer[sizeof(buffer) - 1] = '\0';
72 if (buffer[strlen(buffer) - 1] == '\n') {
73 buffer[strlen(buffer) - 1] = '\0';
74 vty_out(vty, "%s%s", buffer, VTY_NEWLINE);
76 vty_out(vty, "%s", buffer);
80 static struct osmocom_ms *get_ms(const char *name, struct vty *vty)
82 struct osmocom_ms *ms;
84 llist_for_each_entry(ms, &ms_list, entity) {
85 if (!strcmp(ms->name, name))
88 vty_out(vty, "MS name '%s' does not exits.%s", name, VTY_NEWLINE);
93 DEFUN(show_ms, show_ms_cmd, "show ms",
94 SHOW_STR "Display available MS entities\n")
96 struct osmocom_ms *ms;
98 llist_for_each_entry(ms, &ms_list, entity) {
99 struct gsm_settings *set = &ms->settings;
101 vty_out(vty, "MS NAME: %s%s", ms->name, VTY_NEWLINE);
102 vty_out(vty, " IMEI: %s%s", set->imei, VTY_NEWLINE);
103 vty_out(vty, " IMEISV: %s%s", set->imeisv, VTY_NEWLINE);
104 if (set->imei_random)
105 vty_out(vty, " IMEI generation: random (%d trailing "
106 "digits)%s", set->imei_random, VTY_NEWLINE);
108 vty_out(vty, " IMEI generation: fixed%s", VTY_NEWLINE);
109 vty_out(vty, " network selection mode: %s%s",
110 (set->plmn_mode == PLMN_MODE_AUTO)
111 ? "automatic" : "manual", VTY_NEWLINE);
117 DEFUN(show_support, show_support_cmd, "show support [ms_name]",
118 SHOW_STR "Display information about MS support\n"
119 "Name of MS (see \"show ms\")")
121 struct osmocom_ms *ms;
124 ms = get_ms(argv[0], vty);
127 gsm_support_dump(&ms->support, print_vty, vty);
129 llist_for_each_entry(ms, &ms_list, entity) {
130 gsm_support_dump(&ms->support, print_vty, vty);
131 vty_out(vty, "%s", VTY_NEWLINE);
138 static void gsm_states_dump(struct osmocom_ms *ms, struct vty *vty)
140 struct gsm_trans *trans;
142 vty_out(vty, "Current state of MS '%s'%s", ms->name, VTY_NEWLINE);
143 if (ms->settings.plmn_mode == PLMN_MODE_AUTO)
144 vty_out(vty, " automatic network selection: %s%s",
145 plmn_a_state_names[ms->plmn.state], VTY_NEWLINE);
147 vty_out(vty, " manual network selection: %s%s",
148 plmn_m_state_names[ms->plmn.state], VTY_NEWLINE);
149 vty_out(vty, " cell selection: %s%s",
150 cs_state_names[ms->cellsel.state], VTY_NEWLINE);
151 vty_out(vty, " radio ressource layer: %s%s",
152 gsm48_rr_state_names[ms->rrlayer.state], VTY_NEWLINE);
153 vty_out(vty, " mobility management layer: %s",
154 gsm48_mm_state_names[ms->mmlayer.state]);
155 if (ms->mmlayer.state == GSM48_MM_ST_MM_IDLE)
157 gsm48_mm_substate_names[ms->mmlayer.substate]);
158 vty_out(vty, "%s", VTY_NEWLINE);
159 llist_for_each_entry(trans, &ms->trans_list, entry) {
160 vty_out(vty, " call control: %s%s",
161 gsm48_cc_state_name(trans->cc.state), VTY_NEWLINE);
165 DEFUN(show_states, show_states_cmd, "show states [ms_name]",
166 SHOW_STR "Display current states of given MS\n"
167 "Name of MS (see \"show ms\")")
169 struct osmocom_ms *ms;
172 ms = get_ms(argv[0], vty);
175 gsm_states_dump(ms, vty);
177 llist_for_each_entry(ms, &ms_list, entity) {
178 gsm_states_dump(ms, vty);
179 vty_out(vty, "%s", VTY_NEWLINE);
186 DEFUN(show_subscr, show_subscr_cmd, "show subscriber [ms_name]",
187 SHOW_STR "Display information about subscriber\n"
188 "Name of MS (see \"show ms\")")
190 struct osmocom_ms *ms;
193 ms = get_ms(argv[0], vty);
196 gsm_subscr_dump(&ms->subscr, print_vty, vty);
198 llist_for_each_entry(ms, &ms_list, entity) {
199 gsm_subscr_dump(&ms->subscr, print_vty, vty);
200 vty_out(vty, "%s", VTY_NEWLINE);
207 DEFUN(show_cell, show_cell_cmd, "show cell MS_NAME",
208 SHOW_STR "Display information about received cells\n"
209 "Name of MS (see \"show ms\")")
211 struct osmocom_ms *ms;
213 ms = get_ms(argv[0], vty);
217 gsm322_dump_cs_list(&ms->cellsel, GSM322_CS_FLAG_SYSINFO, print_vty,
223 DEFUN(show_cell_si, show_cell_si_cmd, "show cell MS_NAME <0-1023>",
224 SHOW_STR "Display information about received cell\n"
225 "Name of MS (see \"show ms\")\nRadio frequency number")
227 struct osmocom_ms *ms;
229 struct gsm48_sysinfo *s;
231 ms = get_ms(argv[0], vty);
236 if (i < 0 || i > 1023) {
237 vty_out(vty, "Given ARFCN '%s' not in range (0..1023)%s",
238 argv[1], VTY_NEWLINE);
241 s = ms->cellsel.list[i].sysinfo;
243 vty_out(vty, "Given ARFCN '%s' has no sysinfo available%s",
244 argv[1], VTY_NEWLINE);
248 gsm48_sysinfo_dump(s, i, print_vty, vty);
253 DEFUN(show_ba, show_ba_cmd, "show ba MS_NAME [mcc] [mnc]",
254 SHOW_STR "Display information about band allocations\n"
255 "Name of MS (see \"show ms\")\nMobile Country Code\n"
256 "Mobile Network Code")
258 struct osmocom_ms *ms;
259 uint16_t mcc = 0, mnc = 0;
261 ms = get_ms(argv[0], vty);
266 mcc = gsm_input_mcc((char *)argv[1]);
267 mnc = gsm_input_mnc((char *)argv[2]);
269 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
273 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
278 gsm322_dump_ba_list(&ms->cellsel, mcc, mnc, print_vty, vty);
283 DEFUN(show_forb_plmn, show_forb_plmn_cmd, "show forbidden plmn MS_NAME",
284 SHOW_STR "Display information about forbidden cells / networks\n"
285 "Display forbidden PLMNs\nName of MS (see \"show ms\")")
287 struct osmocom_ms *ms;
289 ms = get_ms(argv[0], vty);
293 gsm_subscr_dump_forbidden_plmn(ms, print_vty, vty);
298 DEFUN(show_forb_la, show_forb_la_cmd, "show forbidden location-area MS_NAME",
299 SHOW_STR "Display information about forbidden cells / networks\n"
300 "Display forbidden location areas\nName of MS (see \"show ms\")")
302 struct osmocom_ms *ms;
304 ms = get_ms(argv[0], vty);
308 gsm322_dump_forbidden_la(ms, print_vty, vty);
313 DEFUN(monitor_network, monitor_network_cmd, "monitor network MS_NAME",
314 "Monitor...\nMonitor network information\nName of MS (see \"show ms\")")
316 struct osmocom_ms *ms;
318 ms = get_ms(argv[0], vty);
322 gsm48_rr_start_monitor(ms);
327 DEFUN(no_monitor_network, no_monitor_network_cmd, "no monitor network MS_NAME",
328 NO_STR "Monitor...\nDeactivate monitor of network information\n"
329 "Name of MS (see \"show ms\")")
331 struct osmocom_ms *ms;
333 ms = get_ms(argv[0], vty);
337 gsm48_rr_stop_monitor(ms);
342 DEFUN(sim_test, sim_test_cmd, "sim testcard MS_NAME [mcc] [mnc]",
343 "SIM actions\nInsert test card\nName of MS (see \"show ms\")\n"
344 "Mobile Country Code of RPLMN\nMobile Network Code of RPLMN")
346 struct osmocom_ms *ms;
347 uint16_t mcc = 0x001, mnc = 0x01f;
349 ms = get_ms(argv[0], vty);
353 if (ms->subscr.sim_valid) {
354 vty_out(vty, "SIM already presend, remove first!%s",
360 mcc = gsm_input_mcc((char *)argv[1]);
361 mnc = gsm_input_mnc((char *)argv[2]);
363 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
367 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
372 gsm_subscr_testcard(ms, mcc, mnc);
377 DEFUN(sim_reader, sim_reader_cmd, "sim reader MS_NAME",
378 "SIM actions\nSelect SIM from reader\nName of MS (see \"show ms\")")
380 struct osmocom_ms *ms;
382 ms = get_ms(argv[0], vty);
386 if (ms->subscr.sim_valid) {
387 vty_out(vty, "SIM already presend, remove first!%s",
392 gsm_subscr_simcard(ms);
397 DEFUN(sim_remove, sim_remove_cmd, "sim remove MS_NAME",
398 "SIM actions\nRemove SIM card\nName of MS (see \"show ms\")")
400 struct osmocom_ms *ms;
402 ms = get_ms(argv[0], vty);
406 if (!ms->subscr.sim_valid) {
407 vty_out(vty, "No Sim inserted!%s", VTY_NEWLINE);
411 gsm_subscr_remove(ms);
416 DEFUN(sim_pin, sim_pin_cmd, "sim pin MS_NAME PIN",
417 "SIM actions\nEnter PIN for SIM card\nName of MS (see \"show ms\")\n"
420 struct osmocom_ms *ms;
422 ms = get_ms(argv[0], vty);
426 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
427 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
431 if (!ms->subscr.sim_pin_required) {
432 vty_out(vty, "No PIN is required at this time!%s", VTY_NEWLINE);
436 gsm_subscr_sim_pin(ms, (char *)argv[1], "", 0);
441 DEFUN(sim_disable_pin, sim_disable_pin_cmd, "sim disable-pin MS_NAME PIN",
442 "SIM actions\nDisable PIN of SIM card\nName of MS (see \"show ms\")\n"
445 struct osmocom_ms *ms;
447 ms = get_ms(argv[0], vty);
451 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
452 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
456 gsm_subscr_sim_pin(ms, (char *)argv[1], "", -1);
461 DEFUN(sim_enable_pin, sim_enable_pin_cmd, "sim enable-pin MS_NAME PIN",
462 "SIM actions\nEnable PIN of SIM card\nName of MS (see \"show ms\")\n"
465 struct osmocom_ms *ms;
467 ms = get_ms(argv[0], vty);
471 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
472 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
476 gsm_subscr_sim_pin(ms, (char *)argv[1], "", 1);
481 DEFUN(sim_change_pin, sim_change_pin_cmd, "sim change-pin MS_NAME OLD NEW",
482 "SIM actions\nChange PIN of SIM card\nName of MS (see \"show ms\")\n"
483 "Old PIN number\nNew PIN number")
485 struct osmocom_ms *ms;
487 ms = get_ms(argv[0], vty);
491 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
492 vty_out(vty, "Old PIN must be in range 4..8!%s", VTY_NEWLINE);
495 if (strlen(argv[2]) < 4 || strlen(argv[2]) > 8) {
496 vty_out(vty, "New PIN must be in range 4..8!%s", VTY_NEWLINE);
500 gsm_subscr_sim_pin(ms, (char *)argv[1], (char *)argv[2], 2);
505 DEFUN(sim_unblock_pin, sim_unblock_pin_cmd, "sim unblock-pin MS_NAME PUC NEW",
506 "SIM actions\nChange PIN of SIM card\nName of MS (see \"show ms\")\n"
507 "Personal Unblock Key\nNew PIN number")
509 struct osmocom_ms *ms;
511 ms = get_ms(argv[0], vty);
515 if (strlen(argv[1]) != 8) {
516 vty_out(vty, "PUC must be 8 digits!%s", VTY_NEWLINE);
519 if (strlen(argv[2]) < 4 || strlen(argv[2]) > 8) {
520 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
524 gsm_subscr_sim_pin(ms, (char *)argv[1], (char *)argv[2], 99);
529 DEFUN(network_select, network_select_cmd, "network select MS_NAME MCC MNC",
530 "Select ...\nSelect Network\nName of MS (see \"show ms\")\n"
531 "Mobile Country Code\nMobile Network Code")
533 struct osmocom_ms *ms;
534 struct gsm322_plmn *plmn;
536 struct gsm322_msg *ngm;
537 struct gsm322_plmn_list *temp;
538 uint16_t mcc = gsm_input_mcc((char *)argv[1]),
539 mnc = gsm_input_mnc((char *)argv[2]);
542 ms = get_ms(argv[0], vty);
548 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
552 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
556 llist_for_each_entry(temp, &plmn->sorted_plmn, entry)
557 if (temp->mcc == mcc && temp->mnc == mnc)
560 vty_out(vty, "Network not in list!%s", VTY_NEWLINE);
564 nmsg = gsm322_msgb_alloc(GSM322_EVENT_CHOOSE_PLMN);
567 ngm = (struct gsm322_msg *) nmsg->data;
570 gsm322_plmn_sendmsg(ms, nmsg);
575 DEFUN(call, call_cmd, "call MS_NAME (NUMBER|emergency|answer|hangup|hold)",
576 "Make a call\nName of MS (see \"show ms\")\nPhone number to call "
577 "(Use digits '0123456789*#abc', and '+' to dial international)\n"
578 "Make an emergency call\nAnswer an incomming call\nHangup a call\n"
579 "Hold current active call\n")
581 struct osmocom_ms *ms;
584 ms = get_ms(argv[0], vty);
588 switch (argv[1][0]) {
593 if (argv[1][1] == 'a')
599 for (i = 0; i < strlen(argv[1]); i++) {
600 /* allow international notation with + */
601 if (i == 0 && argv[1][i] == '+')
603 if (!(argv[1][i] >= '0' && argv[1][i] <= '9')
606 && !(argv[1][i] >= 'a' && argv[1][i] <= 'c')) {
607 vty_out(vty, "Invalid digit '%c'%s", argv[1][i],
612 mncc_call(ms, (char *)argv[1]);
618 DEFUN(call_retr, call_retr_cmd, "call MS_NAME retrieve [number]",
619 "Make a call\nName of MS (see \"show ms\")\n"
620 "Retrieve call on hold\nNumber of call to retrieve")
622 struct osmocom_ms *ms;
624 ms = get_ms(argv[0], vty);
628 mncc_retrieve(ms, (argc > 1) ? atoi(argv[1]) : 0);
633 DEFUN(network_show, network_show_cmd, "network show MS_NAME",
634 "Network ...\nShow results of network search (again)\n"
635 "Name of MS (see \"show ms\")")
637 struct osmocom_ms *ms;
638 struct gsm322_plmn *plmn;
639 struct gsm322_plmn_list *temp;
641 ms = get_ms(argv[0], vty);
646 if (ms->settings.plmn_mode != PLMN_MODE_AUTO
647 && plmn->state != GSM322_M3_NOT_ON_PLMN) {
648 vty_out(vty, "Start network search first!%s", VTY_NEWLINE);
652 llist_for_each_entry(temp, &plmn->sorted_plmn, entry)
653 vty_out(vty, " Network %s, %s (%s, %s)%s",
654 gsm_print_mcc(temp->mcc), gsm_print_mnc(temp->mnc),
655 gsm_get_mcc(temp->mcc),
656 gsm_get_mnc(temp->mcc, temp->mnc), VTY_NEWLINE);
661 DEFUN(network_search, network_search_cmd, "network search MS_NAME",
662 "Network ...\nTrigger network search\nName of MS (see \"show ms\")")
664 struct osmocom_ms *ms;
667 ms = get_ms(argv[0], vty);
671 nmsg = gsm322_msgb_alloc(GSM322_EVENT_USER_RESEL);
674 gsm322_plmn_sendmsg(ms, nmsg);
679 DEFUN(cfg_gps_enable, cfg_gps_enable_cmd, "gps enable",
684 vty_out(vty, "Failed to open GPS device!%s", VTY_NEWLINE);
692 DEFUN(cfg_no_gps_enable, cfg_no_gps_enable_cmd, "no gps enable",
693 NO_STR "Disable GPS receiver")
702 DEFUN(cfg_gps_device, cfg_gps_device_cmd, "gps device DEVICE",
703 "GPS receiver\nSelect serial device\n"
704 "Full path of serial device including /dev/")
706 strncpy(gps.device, argv[0], sizeof(gps.device));
707 gps.device[sizeof(gps.device) - 1] = '\0';
711 vty_out(vty, "Failed to open GPS device!%s",
720 DEFUN(cfg_gps_baud, cfg_gps_baud_cmd, "gps baudrate "
721 "(default|4800|""9600|19200|38400|57600|115200)",
722 "GPS receiver\nSelect baud rate\nDefault, don't modify\n\n\n\n\n\n")
724 if (argv[0][0] == 'd')
727 gps.baud = atoi(argv[0]);
732 vty_out(vty, "Failed to open GPS device!%s",
742 DEFUN(cfg_ms, cfg_ms_cmd, "ms MS_NAME",
743 "Select a mobile station to configure\nName of MS (see \"show ms\")")
745 struct osmocom_ms *ms;
747 ms = get_ms(argv[0], vty);
757 static void config_write_ms_single(struct vty *vty, struct osmocom_ms *ms)
759 struct gsm_settings *set = &ms->settings;
761 vty_out(vty, "ms %s%s", ms->name, VTY_NEWLINE);
762 switch(set->sim_type) {
763 case GSM_SIM_TYPE_NONE:
764 vty_out(vty, " sim none%s", VTY_NEWLINE);
766 case GSM_SIM_TYPE_READER:
767 vty_out(vty, " sim reader%s", VTY_NEWLINE);
769 case GSM_SIM_TYPE_TEST:
770 vty_out(vty, " sim test%s", VTY_NEWLINE);
773 vty_out(vty, " network-selection-mode %s%s", (set->plmn_mode
774 == PLMN_MODE_AUTO) ? "auto" : "manual", VTY_NEWLINE);
775 vty_out(vty, " imei %s %s%s", set->imei,
776 set->imeisv + strlen(set->imei), VTY_NEWLINE);
777 if (set->imei_random)
778 vty_out(vty, " imei-random %d%s", set->imei_random,
781 vty_out(vty, " imei-fixed%s", VTY_NEWLINE);
782 if (set->emergency_imsi[0])
783 vty_out(vty, " emergency-imsi %s%s", set->emergency_imsi,
786 vty_out(vty, " no emergency-imsi%s", VTY_NEWLINE);
787 vty_out(vty, " %scall-waiting%s", (set->cw) ? "" : "no ", VTY_NEWLINE);
788 vty_out(vty, " %sclip%s", (set->clip) ? "" : "no ", VTY_NEWLINE);
789 vty_out(vty, " %sclir%s", (set->clir) ? "" : "no ", VTY_NEWLINE);
790 vty_out(vty, " test-sim%s", VTY_NEWLINE);
791 vty_out(vty, " imsi %s%s", set->test_imsi, VTY_NEWLINE);
792 switch (set->test_ki_type) {
793 case GSM_SIM_KEY_XOR:
794 vty_out(vty, " ki xor %s%s", hexdump(set->test_ki, 12),
797 case GSM_SIM_KEY_COMP128:
798 vty_out(vty, " ki comp128 %s%s", hexdump(set->test_ki, 16),
802 vty_out(vty, " %sbarred-access%s", (set->test_barr) ? "" : "no ",
804 if (set->test_rplmn_valid)
805 vty_out(vty, " rplmn %s %s%s",
806 gsm_print_mcc(set->test_rplmn_mcc),
807 gsm_print_mnc(set->test_rplmn_mnc),
810 vty_out(vty, " no rplmn%s", VTY_NEWLINE);
811 vty_out(vty, " hplmn-search %s%s", (set->test_always) ? "everywhere"
812 : "foreign-country", VTY_NEWLINE);
813 vty_out(vty, " exit%s", VTY_NEWLINE);
814 if (set->alter_tx_power)
815 if (set->alter_tx_power_value)
816 vty_out(vty, " tx-power %d%s",
817 set->alter_tx_power_value, VTY_NEWLINE);
819 vty_out(vty, " tx-power full%s", VTY_NEWLINE);
821 vty_out(vty, " tx-power auto%s", VTY_NEWLINE);
822 if (set->alter_delay)
823 vty_out(vty, " simulated-delay %d%s", set->alter_delay,
826 vty_out(vty, " no simulated-delay%s", VTY_NEWLINE);
828 vty_out(vty, " stick %d%s", set->stick_arfcn,
831 vty_out(vty, " no stick%s", VTY_NEWLINE);
833 vty_out(vty, " no location-updating%s", VTY_NEWLINE);
835 vty_out(vty, " location-updating%s", VTY_NEWLINE);
836 vty_out(vty, "exit%s", VTY_NEWLINE);
837 vty_out(vty, "!%s", VTY_NEWLINE);
840 static int config_write_ms(struct vty *vty)
842 struct osmocom_ms *ms;
844 vty_out(vty, "gps device %s%s", gps.device, VTY_NEWLINE);
846 vty_out(vty, "gps baudrate %d%s", gps.baud, VTY_NEWLINE);
848 vty_out(vty, "gps baudrate default%s", VTY_NEWLINE);
849 vty_out(vty, "%sgps enable%s", (gps.enable) ? "" : "no ", VTY_NEWLINE);
850 vty_out(vty, "!%s", VTY_NEWLINE);
852 llist_for_each_entry(ms, &ms_list, entity)
853 config_write_ms_single(vty, ms);
858 DEFUN(cfg_ms_sim, cfg_ms_sim_cmd, "sim (none|reader|test)",
859 "Set SIM card type when powering on\nNo SIM interted\n"
860 "Use SIM from reader\nTest SIM inserted")
862 struct osmocom_ms *ms = vty->index;
864 switch (argv[0][0]) {
866 ms->settings.sim_type = GSM_SIM_TYPE_NONE;
869 ms->settings.sim_type = GSM_SIM_TYPE_READER;
872 ms->settings.sim_type = GSM_SIM_TYPE_TEST;
875 vty_out(vty, "unknown SIM type%s", VTY_NEWLINE);
882 DEFUN(cfg_ms_mode, cfg_ms_mode_cmd, "network-selection-mode (auto|manual)",
883 "Set network selection mode\nAutomatic network selection\n"
884 "Manual network selection")
886 struct osmocom_ms *ms = vty->index;
889 if (!ms->plmn.state) {
890 if (argv[0][0] == 'a')
891 ms->settings.plmn_mode = PLMN_MODE_AUTO;
893 ms->settings.plmn_mode = PLMN_MODE_MANUAL;
897 if (argv[0][0] == 'a')
898 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SEL_AUTO);
900 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SEL_MANUAL);
903 gsm322_plmn_sendmsg(ms, nmsg);
908 DEFUN(cfg_ms_imei, cfg_ms_imei_cmd, "imei IMEI [SV]",
909 "Set IMEI (enter without control digit)\n15 Digits IMEI\n"
910 "Software version digit")
912 struct osmocom_ms *ms = vty->index;
913 char *error, *sv = "0";
916 sv = (char *)argv[1];
918 error = gsm_check_imei(argv[0], sv);
920 vty_out(vty, "%s%s", error, VTY_NEWLINE);
924 strcpy(ms->settings.imei, argv[0]);
925 strcpy(ms->settings.imeisv, argv[0]);
926 strcpy(ms->settings.imeisv + 15, sv);
931 DEFUN(cfg_ms_imei_fixed, cfg_ms_imei_fixed_cmd, "imei-fixed",
932 "Use fixed IMEI on every power on")
934 struct osmocom_ms *ms = vty->index;
936 ms->settings.imei_random = 0;
941 DEFUN(cfg_ms_imei_random, cfg_ms_imei_random_cmd, "imei-random <0-15>",
942 "Use random IMEI on every power on\n"
943 "Number of trailing digits to randomize")
945 struct osmocom_ms *ms = vty->index;
947 ms->settings.imei_random = atoi(argv[0]);
952 DEFUN(cfg_ms_emerg_imsi, cfg_ms_emerg_imsi_cmd, "emergency-imsi IMSI",
953 "Use special IMSI for emergency calls\n15 digits IMSI")
955 struct osmocom_ms *ms = vty->index;
958 error = gsm_check_imsi(argv[0]);
960 vty_out(vty, "%s%s", error, VTY_NEWLINE);
963 strcpy(ms->settings.emergency_imsi, argv[0]);
968 DEFUN(cfg_ms_no_emerg_imsi, cfg_ms_no_emerg_imsi_cmd, "no emergency-imsi",
969 NO_STR "Use IMSI of SIM or IMEI for emergency calls")
971 struct osmocom_ms *ms = vty->index;
973 ms->settings.emergency_imsi[0] = '\0';
978 DEFUN(cfg_no_cw, cfg_ms_no_cw_cmd, "no call-waiting",
979 NO_STR "Disallow waiting calls")
981 struct osmocom_ms *ms = vty->index;
988 DEFUN(cfg_cw, cfg_ms_cw_cmd, "call-waiting",
989 "Allow waiting calls")
991 struct osmocom_ms *ms = vty->index;
998 DEFUN(cfg_clip, cfg_ms_clip_cmd, "clip",
999 "Force caller ID presentation")
1001 struct osmocom_ms *ms = vty->index;
1003 ms->settings.clip = 1;
1004 ms->settings.clir = 0;
1009 DEFUN(cfg_clir, cfg_ms_clir_cmd, "clir",
1010 "Force caller ID restriction")
1012 struct osmocom_ms *ms = vty->index;
1014 ms->settings.clip = 0;
1015 ms->settings.clir = 1;
1020 DEFUN(cfg_no_clip, cfg_ms_no_clip_cmd, "no clip",
1021 NO_STR "Disable forcing of caller ID presentation")
1023 struct osmocom_ms *ms = vty->index;
1025 ms->settings.clip = 0;
1030 DEFUN(cfg_no_clir, cfg_ms_no_clir_cmd, "no clir",
1031 NO_STR "Disable forcing of caller ID restriction")
1033 struct osmocom_ms *ms = vty->index;
1035 ms->settings.clir = 0;
1040 DEFUN(cfg_ms_tx_power, cfg_ms_tx_power_cmd, "tx-power (auto|full)",
1041 "Set the way to choose transmit power\nControlled by BTS\n"
1042 "Always full power\nFixed GSM power value if supported")
1044 struct osmocom_ms *ms = vty->index;
1046 switch (argv[0][0]) {
1048 ms->settings.alter_tx_power = 0;
1051 ms->settings.alter_tx_power = 1;
1052 ms->settings.alter_tx_power_value = 0;
1059 DEFUN(cfg_ms_tx_power_val, cfg_ms_tx_power_val_cmd, "tx-power <0-31>",
1060 "Set the way to choose transmit power\n"
1061 "Fixed GSM power value if supported")
1063 struct osmocom_ms *ms = vty->index;
1065 ms->settings.alter_tx_power = 1;
1066 ms->settings.alter_tx_power_value = atoi(argv[0]);
1071 DEFUN(cfg_ms_sim_delay, cfg_ms_sim_delay_cmd, "simulated-delay <-128-127>",
1072 "Simulate a lower or higher distance from the BTS\n"
1073 "Delay in half bits (distance in 553.85 meter steps)")
1075 struct osmocom_ms *ms = vty->index;
1077 ms->settings.alter_delay = atoi(argv[0]);
1082 DEFUN(cfg_ms_no_sim_delay, cfg_ms_no_sim_delay_cmd, "no simulated-delay",
1083 NO_STR "Do not simulate a lower or higher distance from the BTS")
1085 struct osmocom_ms *ms = vty->index;
1087 ms->settings.alter_delay = 0;
1092 DEFUN(cfg_ms_stick, cfg_ms_stick_cmd, "stick <0-1023>",
1093 "Stick to the given cell\nARFCN of the cell to stick to")
1095 struct osmocom_ms *ms = vty->index;
1097 ms->settings.stick = 1;
1098 ms->settings.stick_arfcn = atoi(argv[0]);
1103 DEFUN(cfg_ms_no_stick, cfg_ms_no_stick_cmd, "no stick",
1104 NO_STR "Do not stick to any cell")
1106 struct osmocom_ms *ms = vty->index;
1108 ms->settings.stick = 0;
1113 DEFUN(cfg_ms_lupd, cfg_ms_lupd_cmd, "location-updating",
1114 "Allow location updating")
1116 struct osmocom_ms *ms = vty->index;
1118 ms->settings.no_lupd = 0;
1123 DEFUN(cfg_ms_no_lupd, cfg_ms_no_lupd_cmd, "no location-updating",
1124 NO_STR "Do not allow location updating")
1126 struct osmocom_ms *ms = vty->index;
1128 ms->settings.no_lupd = 1;
1133 /* per testsim config */
1134 DEFUN(cfg_ms_testsim, cfg_ms_testsim_cmd, "test-sim",
1135 "Configure test SIM emulation")
1137 vty->node = TESTSIM_NODE;
1142 static int config_write_dummy(struct vty *vty)
1147 DEFUN(cfg_test_imsi, cfg_test_imsi_cmd, "imsi IMSI",
1148 "Set IMSI on test card\n15 digits IMSI")
1150 struct osmocom_ms *ms = vty->index;
1151 char *error = gsm_check_imsi(argv[0]);
1154 vty_out(vty, "%s%s", error, VTY_NEWLINE);
1158 strcpy(ms->settings.test_imsi, argv[0]);
1163 #define HEX_STR "\nByte as two digits hexadecimal"
1164 DEFUN(cfg_test_ki_xor, cfg_test_ki_xor_cmd, "ki xor HEX HEX HEX HEX HEX HEX "
1165 "HEX HEX HEX HEX HEX HEX",
1166 "Set Key (Kc) on test card\nUse XOR algorithm" HEX_STR HEX_STR HEX_STR
1167 HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR)
1169 struct osmocom_ms *ms = vty->index;
1170 struct gsm_settings *set = &ms->settings;
1175 for (i = 0; i < 12; i++) {
1177 if (!strncmp(p, "0x", 2))
1179 if (strlen(p) != 2) {
1180 vty_out(vty, "Expecting two digits hex value (with or "
1181 "without 0x in front)%s", VTY_NEWLINE);
1184 ki[i] = strtoul(p, NULL, 16);
1187 set->test_ki_type = GSM_SIM_KEY_XOR;
1188 memcpy(set->test_ki, ki, 12);
1192 DEFUN(cfg_test_ki_comp128, cfg_test_ki_comp128_cmd, "ki comp128 HEX HEX HEX "
1193 "HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX",
1194 "Set Key (Kc) on test card\nUse XOR algorithm" HEX_STR HEX_STR HEX_STR
1195 HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR
1196 HEX_STR HEX_STR HEX_STR HEX_STR)
1198 struct osmocom_ms *ms = vty->index;
1199 struct gsm_settings *set = &ms->settings;
1204 for (i = 0; i < 16; i++) {
1206 if (!strncmp(p, "0x", 2))
1208 if (strlen(p) != 2) {
1209 vty_out(vty, "Expecting two digits hex value (with or "
1210 "without 0x in front)%s", VTY_NEWLINE);
1213 ki[i] = strtoul(p, NULL, 16);
1216 set->test_ki_type = GSM_SIM_KEY_COMP128;
1217 memcpy(set->test_ki, ki, 16);
1221 DEFUN(cfg_test_barr, cfg_test_barr_cmd, "barred-access",
1222 "Allow access to barred cells")
1224 struct osmocom_ms *ms = vty->index;
1226 ms->settings.test_barr = 1;
1231 DEFUN(cfg_test_no_barr, cfg_test_no_barr_cmd, "no barred-access",
1232 NO_STR "Deny access to barred cells")
1234 struct osmocom_ms *ms = vty->index;
1236 ms->settings.test_barr = 0;
1241 DEFUN(cfg_test_no_rplmn, cfg_test_no_rplmn_cmd, "no rplmn",
1242 NO_STR "Unset Registered PLMN")
1244 struct osmocom_ms *ms = vty->index;
1246 ms->settings.test_rplmn_valid = 0;
1251 DEFUN(cfg_test_rplmn, cfg_test_rplmn_cmd, "rplmn MCC MNC",
1252 "Set Registered PLMN\nMobile Country Code\nMobile Network Code")
1254 struct osmocom_ms *ms = vty->index;
1255 uint16_t mcc = gsm_input_mcc((char *)argv[0]),
1256 mnc = gsm_input_mnc((char *)argv[1]);
1259 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
1263 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
1266 ms->settings.test_rplmn_valid = 1;
1267 ms->settings.test_rplmn_mcc = mcc;
1268 ms->settings.test_rplmn_mnc = mnc;
1273 DEFUN(cfg_test_hplmn, cfg_test_hplmn_cmd, "hplmn-search (everywhere|foreign-country)",
1274 "Set Home PLMN search mode\n"
1275 "Search for HPLMN when on any other network\n"
1276 "Search for HPLMN when in a different country")
1278 struct osmocom_ms *ms = vty->index;
1280 switch (argv[0][0]) {
1282 ms->settings.test_always = 1;
1285 ms->settings.test_always = 0;
1292 enum node_type ms_vty_go_parent(struct vty *vty)
1294 switch (vty->node) {
1296 vty->node = CONFIG_NODE;
1300 vty->node = MS_NODE;
1303 vty->node = CONFIG_NODE;
1309 /* Down vty node level. */
1310 gDEFUN(ournode_exit,
1311 ournode_exit_cmd, "exit", "Exit current mode and down to previous mode\n")
1313 switch (vty->node) {
1315 vty->node = CONFIG_NODE;
1319 vty->node = MS_NODE;
1327 /* End of configuration. */
1329 ournode_end_cmd, "end", "End current mode and change to enable mode.")
1331 switch (vty->node) {
1334 /* Nothing to do. */
1340 vty_config_unlock(vty);
1341 vty->node = ENABLE_NODE;
1343 vty->index_sub = NULL;
1351 int ms_vty_init(void)
1353 install_element_ve(&show_ms_cmd);
1354 install_element_ve(&show_subscr_cmd);
1355 install_element_ve(&show_support_cmd);
1356 install_element_ve(&show_states_cmd);
1357 install_element_ve(&show_cell_cmd);
1358 install_element_ve(&show_cell_si_cmd);
1359 install_element_ve(&show_ba_cmd);
1360 install_element_ve(&show_forb_la_cmd);
1361 install_element_ve(&show_forb_plmn_cmd);
1362 install_element_ve(&monitor_network_cmd);
1363 install_element_ve(&no_monitor_network_cmd);
1365 install_element(ENABLE_NODE, &sim_test_cmd);
1366 install_element(ENABLE_NODE, &sim_reader_cmd);
1367 install_element(ENABLE_NODE, &sim_remove_cmd);
1368 install_element(ENABLE_NODE, &sim_pin_cmd);
1369 install_element(ENABLE_NODE, &sim_disable_pin_cmd);
1370 install_element(ENABLE_NODE, &sim_enable_pin_cmd);
1371 install_element(ENABLE_NODE, &sim_change_pin_cmd);
1372 install_element(ENABLE_NODE, &sim_unblock_pin_cmd);
1373 install_element(ENABLE_NODE, &network_search_cmd);
1374 install_element(ENABLE_NODE, &network_show_cmd);
1375 install_element(ENABLE_NODE, &network_select_cmd);
1376 install_element(ENABLE_NODE, &call_cmd);
1377 install_element(ENABLE_NODE, &call_retr_cmd);
1379 install_element(CONFIG_NODE, &cfg_gps_device_cmd);
1380 install_element(CONFIG_NODE, &cfg_gps_baud_cmd);
1381 install_element(CONFIG_NODE, &cfg_gps_enable_cmd);
1382 install_element(CONFIG_NODE, &cfg_no_gps_enable_cmd);
1384 install_element(CONFIG_NODE, &cfg_ms_cmd);
1385 install_element(CONFIG_NODE, &ournode_end_cmd);
1386 install_node(&ms_node, config_write_ms);
1387 install_default(MS_NODE);
1388 install_element(MS_NODE, &ournode_exit_cmd);
1389 install_element(MS_NODE, &ournode_end_cmd);
1390 install_element(MS_NODE, &cfg_ms_sim_cmd);
1391 install_element(MS_NODE, &cfg_ms_mode_cmd);
1392 install_element(MS_NODE, &cfg_ms_imei_cmd);
1393 install_element(MS_NODE, &cfg_ms_imei_fixed_cmd);
1394 install_element(MS_NODE, &cfg_ms_imei_random_cmd);
1395 install_element(MS_NODE, &cfg_ms_no_emerg_imsi_cmd);
1396 install_element(MS_NODE, &cfg_ms_emerg_imsi_cmd);
1397 install_element(MS_NODE, &cfg_ms_cw_cmd);
1398 install_element(MS_NODE, &cfg_ms_no_cw_cmd);
1399 install_element(MS_NODE, &cfg_ms_clip_cmd);
1400 install_element(MS_NODE, &cfg_ms_clir_cmd);
1401 install_element(MS_NODE, &cfg_ms_no_clip_cmd);
1402 install_element(MS_NODE, &cfg_ms_no_clir_cmd);
1403 install_element(MS_NODE, &cfg_ms_testsim_cmd);
1404 install_element(MS_NODE, &cfg_ms_tx_power_cmd);
1405 install_element(MS_NODE, &cfg_ms_tx_power_val_cmd);
1406 install_element(MS_NODE, &cfg_ms_sim_delay_cmd);
1407 install_element(MS_NODE, &cfg_ms_no_sim_delay_cmd);
1408 install_element(MS_NODE, &cfg_ms_stick_cmd);
1409 install_element(MS_NODE, &cfg_ms_no_stick_cmd);
1410 install_element(MS_NODE, &cfg_ms_lupd_cmd);
1411 install_element(MS_NODE, &cfg_ms_no_lupd_cmd);
1413 install_node(&testsim_node, config_write_dummy);
1414 install_default(TESTSIM_NODE);
1415 install_element(TESTSIM_NODE, &ournode_exit_cmd);
1416 install_element(TESTSIM_NODE, &ournode_end_cmd);
1417 install_element(TESTSIM_NODE, &cfg_test_imsi_cmd);
1418 install_element(TESTSIM_NODE, &cfg_test_ki_xor_cmd);
1419 install_element(TESTSIM_NODE, &cfg_test_ki_comp128_cmd);
1420 install_element(TESTSIM_NODE, &cfg_test_barr_cmd);
1421 install_element(TESTSIM_NODE, &cfg_test_no_barr_cmd);
1422 install_element(TESTSIM_NODE, &cfg_test_no_rplmn_cmd);
1423 install_element(TESTSIM_NODE, &cfg_test_rplmn_cmd);
1424 install_element(TESTSIM_NODE, &cfg_test_hplmn_cmd);
1429 void vty_notify(struct osmocom_ms *ms, const char *fmt, ...)
1431 struct telnet_connection *connection;
1437 va_start(args, fmt);
1438 vsnprintf(buffer, sizeof(buffer) - 1, fmt, args);
1439 buffer[sizeof(buffer) - 1] = '\0';
1446 llist_for_each_entry(connection, &active_connections, entry) {
1447 vty = connection->vty;
1451 vty_out(vty, "%s%% (MS %s)%s", VTY_NEWLINE, ms->name,
1455 if (buffer[strlen(buffer) - 1] == '\n') {
1456 buffer[strlen(buffer) - 1] = '\0';
1457 vty_out(vty, "%% %s%s", buffer, VTY_NEWLINE);
1458 buffer[strlen(buffer)] = '\n';
1460 vty_out(vty, "%% %s", buffer);