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 struct cmd_node support_node = {
66 static void print_vty(void *priv, const char *fmt, ...)
69 struct vty *vty = priv;
73 vsnprintf(buffer, sizeof(buffer) - 1, fmt, args);
74 buffer[sizeof(buffer) - 1] = '\0';
78 if (buffer[strlen(buffer) - 1] == '\n') {
79 buffer[strlen(buffer) - 1] = '\0';
80 vty_out(vty, "%s%s", buffer, VTY_NEWLINE);
82 vty_out(vty, "%s", buffer);
88 static void vty_restart(struct vty *vty)
92 vty_out(vty, "You must restart for change to take effect!%s",
96 static struct osmocom_ms *get_ms(const char *name, struct vty *vty)
98 struct osmocom_ms *ms;
100 llist_for_each_entry(ms, &ms_list, entity) {
101 if (!strcmp(ms->name, name))
104 vty_out(vty, "MS name '%s' does not exits.%s", name, VTY_NEWLINE);
109 DEFUN(show_ms, show_ms_cmd, "show ms",
110 SHOW_STR "Display available MS entities\n")
112 struct osmocom_ms *ms;
114 llist_for_each_entry(ms, &ms_list, entity) {
115 struct gsm_settings *set = &ms->settings;
117 vty_out(vty, "MS NAME: %s%s", ms->name, VTY_NEWLINE);
118 vty_out(vty, " IMEI: %s%s", set->imei, VTY_NEWLINE);
119 vty_out(vty, " IMEISV: %s%s", set->imeisv, VTY_NEWLINE);
120 if (set->imei_random)
121 vty_out(vty, " IMEI generation: random (%d trailing "
122 "digits)%s", set->imei_random, VTY_NEWLINE);
124 vty_out(vty, " IMEI generation: fixed%s", VTY_NEWLINE);
125 vty_out(vty, " network selection mode: %s%s",
126 (set->plmn_mode == PLMN_MODE_AUTO)
127 ? "automatic" : "manual", VTY_NEWLINE);
133 DEFUN(show_support, show_support_cmd, "show support [ms_name]",
134 SHOW_STR "Display information about MS support\n"
135 "Name of MS (see \"show ms\")")
137 struct osmocom_ms *ms;
140 ms = get_ms(argv[0], vty);
143 gsm_support_dump(ms, print_vty, vty);
145 llist_for_each_entry(ms, &ms_list, entity) {
146 gsm_support_dump(ms, print_vty, vty);
147 vty_out(vty, "%s", VTY_NEWLINE);
154 static void gsm_states_dump(struct osmocom_ms *ms, struct vty *vty)
156 struct gsm_settings *set = &ms->settings;
157 struct gsm_trans *trans;
159 vty_out(vty, "Current state of MS '%s'%s", ms->name, VTY_NEWLINE);
160 if (set->plmn_mode == PLMN_MODE_AUTO)
161 vty_out(vty, " automatic network selection: %s%s",
162 plmn_a_state_names[ms->plmn.state], VTY_NEWLINE);
164 vty_out(vty, " manual network selection: %s%s",
165 plmn_m_state_names[ms->plmn.state], VTY_NEWLINE);
166 vty_out(vty, " cell selection: %s%s",
167 cs_state_names[ms->cellsel.state], VTY_NEWLINE);
168 vty_out(vty, " radio ressource layer: %s%s",
169 gsm48_rr_state_names[ms->rrlayer.state], VTY_NEWLINE);
170 vty_out(vty, " mobility management layer: %s",
171 gsm48_mm_state_names[ms->mmlayer.state]);
172 if (ms->mmlayer.state == GSM48_MM_ST_MM_IDLE)
174 gsm48_mm_substate_names[ms->mmlayer.substate]);
175 vty_out(vty, "%s", VTY_NEWLINE);
176 llist_for_each_entry(trans, &ms->trans_list, entry) {
177 vty_out(vty, " call control: %s%s",
178 gsm48_cc_state_name(trans->cc.state), VTY_NEWLINE);
182 DEFUN(show_states, show_states_cmd, "show states [ms_name]",
183 SHOW_STR "Display current states of given MS\n"
184 "Name of MS (see \"show ms\")")
186 struct osmocom_ms *ms;
189 ms = get_ms(argv[0], vty);
192 gsm_states_dump(ms, vty);
194 llist_for_each_entry(ms, &ms_list, entity) {
195 gsm_states_dump(ms, vty);
196 vty_out(vty, "%s", VTY_NEWLINE);
203 DEFUN(show_subscr, show_subscr_cmd, "show subscriber [ms_name]",
204 SHOW_STR "Display information about subscriber\n"
205 "Name of MS (see \"show ms\")")
207 struct osmocom_ms *ms;
210 ms = get_ms(argv[0], vty);
213 gsm_subscr_dump(&ms->subscr, print_vty, vty);
215 llist_for_each_entry(ms, &ms_list, entity) {
216 gsm_subscr_dump(&ms->subscr, print_vty, vty);
217 vty_out(vty, "%s", VTY_NEWLINE);
224 DEFUN(show_cell, show_cell_cmd, "show cell MS_NAME",
225 SHOW_STR "Display information about received cells\n"
226 "Name of MS (see \"show ms\")")
228 struct osmocom_ms *ms;
230 ms = get_ms(argv[0], vty);
234 gsm322_dump_cs_list(&ms->cellsel, GSM322_CS_FLAG_SYSINFO, print_vty,
240 DEFUN(show_cell_si, show_cell_si_cmd, "show cell MS_NAME <0-1023>",
241 SHOW_STR "Display information about received cell\n"
242 "Name of MS (see \"show ms\")\nRadio frequency number")
244 struct osmocom_ms *ms;
246 struct gsm48_sysinfo *s;
248 ms = get_ms(argv[0], vty);
253 if (i < 0 || i > 1023) {
254 vty_out(vty, "Given ARFCN '%s' not in range (0..1023)%s",
255 argv[1], VTY_NEWLINE);
258 s = ms->cellsel.list[i].sysinfo;
260 vty_out(vty, "Given ARFCN '%s' has no sysinfo available%s",
261 argv[1], VTY_NEWLINE);
265 gsm48_sysinfo_dump(s, i, print_vty, vty);
270 DEFUN(show_ba, show_ba_cmd, "show ba MS_NAME [mcc] [mnc]",
271 SHOW_STR "Display information about band allocations\n"
272 "Name of MS (see \"show ms\")\nMobile Country Code\n"
273 "Mobile Network Code")
275 struct osmocom_ms *ms;
276 uint16_t mcc = 0, mnc = 0;
278 ms = get_ms(argv[0], vty);
283 mcc = gsm_input_mcc((char *)argv[1]);
284 mnc = gsm_input_mnc((char *)argv[2]);
286 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
290 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
295 gsm322_dump_ba_list(&ms->cellsel, mcc, mnc, print_vty, vty);
300 DEFUN(show_forb_plmn, show_forb_plmn_cmd, "show forbidden plmn MS_NAME",
301 SHOW_STR "Display information about forbidden cells / networks\n"
302 "Display forbidden PLMNs\nName of MS (see \"show ms\")")
304 struct osmocom_ms *ms;
306 ms = get_ms(argv[0], vty);
310 gsm_subscr_dump_forbidden_plmn(ms, print_vty, vty);
315 DEFUN(show_forb_la, show_forb_la_cmd, "show forbidden location-area MS_NAME",
316 SHOW_STR "Display information about forbidden cells / networks\n"
317 "Display forbidden location areas\nName of MS (see \"show ms\")")
319 struct osmocom_ms *ms;
321 ms = get_ms(argv[0], vty);
325 gsm322_dump_forbidden_la(ms, print_vty, vty);
330 DEFUN(monitor_network, monitor_network_cmd, "monitor network MS_NAME",
331 "Monitor...\nMonitor network information\nName of MS (see \"show ms\")")
333 struct osmocom_ms *ms;
335 ms = get_ms(argv[0], vty);
339 gsm48_rr_start_monitor(ms);
344 DEFUN(no_monitor_network, no_monitor_network_cmd, "no monitor network MS_NAME",
345 NO_STR "Monitor...\nDeactivate monitor of network information\n"
346 "Name of MS (see \"show ms\")")
348 struct osmocom_ms *ms;
350 ms = get_ms(argv[0], vty);
354 gsm48_rr_stop_monitor(ms);
359 DEFUN(sim_test, sim_test_cmd, "sim testcard MS_NAME [mcc] [mnc]",
360 "SIM actions\nInsert test card\nName of MS (see \"show ms\")\n"
361 "Mobile Country Code of RPLMN\nMobile Network Code of RPLMN")
363 struct osmocom_ms *ms;
364 uint16_t mcc = 0x001, mnc = 0x01f;
366 ms = get_ms(argv[0], vty);
370 if (ms->subscr.sim_valid) {
371 vty_out(vty, "SIM already presend, remove first!%s",
377 mcc = gsm_input_mcc((char *)argv[1]);
378 mnc = gsm_input_mnc((char *)argv[2]);
380 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
384 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
389 gsm_subscr_testcard(ms, mcc, mnc);
394 DEFUN(sim_reader, sim_reader_cmd, "sim reader MS_NAME",
395 "SIM actions\nSelect SIM from reader\nName of MS (see \"show ms\")")
397 struct osmocom_ms *ms;
399 ms = get_ms(argv[0], vty);
403 if (ms->subscr.sim_valid) {
404 vty_out(vty, "SIM already presend, remove first!%s",
409 gsm_subscr_simcard(ms);
414 DEFUN(sim_remove, sim_remove_cmd, "sim remove MS_NAME",
415 "SIM actions\nRemove SIM card\nName of MS (see \"show ms\")")
417 struct osmocom_ms *ms;
419 ms = get_ms(argv[0], vty);
423 if (!ms->subscr.sim_valid) {
424 vty_out(vty, "No Sim inserted!%s", VTY_NEWLINE);
428 gsm_subscr_remove(ms);
433 DEFUN(sim_pin, sim_pin_cmd, "sim pin MS_NAME PIN",
434 "SIM actions\nEnter PIN for SIM card\nName of MS (see \"show ms\")\n"
437 struct osmocom_ms *ms;
439 ms = get_ms(argv[0], vty);
443 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
444 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
448 if (!ms->subscr.sim_pin_required) {
449 vty_out(vty, "No PIN is required at this time!%s", VTY_NEWLINE);
453 gsm_subscr_sim_pin(ms, (char *)argv[1], "", 0);
458 DEFUN(sim_disable_pin, sim_disable_pin_cmd, "sim disable-pin MS_NAME PIN",
459 "SIM actions\nDisable PIN of SIM card\nName of MS (see \"show ms\")\n"
462 struct osmocom_ms *ms;
464 ms = get_ms(argv[0], vty);
468 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
469 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
473 gsm_subscr_sim_pin(ms, (char *)argv[1], "", -1);
478 DEFUN(sim_enable_pin, sim_enable_pin_cmd, "sim enable-pin MS_NAME PIN",
479 "SIM actions\nEnable PIN of SIM card\nName of MS (see \"show ms\")\n"
482 struct osmocom_ms *ms;
484 ms = get_ms(argv[0], vty);
488 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
489 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
493 gsm_subscr_sim_pin(ms, (char *)argv[1], "", 1);
498 DEFUN(sim_change_pin, sim_change_pin_cmd, "sim change-pin MS_NAME OLD NEW",
499 "SIM actions\nChange PIN of SIM card\nName of MS (see \"show ms\")\n"
500 "Old PIN number\nNew PIN number")
502 struct osmocom_ms *ms;
504 ms = get_ms(argv[0], vty);
508 if (strlen(argv[1]) < 4 || strlen(argv[1]) > 8) {
509 vty_out(vty, "Old PIN must be in range 4..8!%s", VTY_NEWLINE);
512 if (strlen(argv[2]) < 4 || strlen(argv[2]) > 8) {
513 vty_out(vty, "New PIN must be in range 4..8!%s", VTY_NEWLINE);
517 gsm_subscr_sim_pin(ms, (char *)argv[1], (char *)argv[2], 2);
522 DEFUN(sim_unblock_pin, sim_unblock_pin_cmd, "sim unblock-pin MS_NAME PUC NEW",
523 "SIM actions\nChange PIN of SIM card\nName of MS (see \"show ms\")\n"
524 "Personal Unblock Key\nNew PIN number")
526 struct osmocom_ms *ms;
528 ms = get_ms(argv[0], vty);
532 if (strlen(argv[1]) != 8) {
533 vty_out(vty, "PUC must be 8 digits!%s", VTY_NEWLINE);
536 if (strlen(argv[2]) < 4 || strlen(argv[2]) > 8) {
537 vty_out(vty, "PIN must be in range 4..8!%s", VTY_NEWLINE);
541 gsm_subscr_sim_pin(ms, (char *)argv[1], (char *)argv[2], 99);
546 DEFUN(sim_lai, sim_lai_cmd, "sim lai MS_NAME MCC MNC LAC",
547 "SIM actions\nChange LAI of SIM card\nName of MS (see \"show ms\")\n"
548 "Mobile Country Code\nMobile Network Code\nLocation Area Code "
549 " (use 0000 to remove LAI)")
551 struct osmocom_ms *ms;
552 uint16_t mcc = gsm_input_mcc((char *)argv[1]),
553 mnc = gsm_input_mnc((char *)argv[2]),
554 lac = strtoul(argv[3], NULL, 16);
556 ms = get_ms(argv[0], vty);
561 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
565 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
569 ms->subscr.mcc = mcc;
570 ms->subscr.mnc = mnc;
571 ms->subscr.lac = lac;
572 ms->subscr.tmsi = 0xffffffff;
574 gsm_subscr_write_loci(ms);
579 DEFUN(network_select, network_select_cmd, "network select MS_NAME MCC MNC",
580 "Select ...\nSelect Network\nName of MS (see \"show ms\")\n"
581 "Mobile Country Code\nMobile Network Code")
583 struct osmocom_ms *ms;
584 struct gsm322_plmn *plmn;
586 struct gsm322_msg *ngm;
587 struct gsm322_plmn_list *temp;
588 uint16_t mcc = gsm_input_mcc((char *)argv[1]),
589 mnc = gsm_input_mnc((char *)argv[2]);
592 ms = get_ms(argv[0], vty);
598 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
602 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
606 llist_for_each_entry(temp, &plmn->sorted_plmn, entry)
607 if (temp->mcc == mcc && temp->mnc == mnc)
610 vty_out(vty, "Network not in list!%s", VTY_NEWLINE);
614 nmsg = gsm322_msgb_alloc(GSM322_EVENT_CHOOSE_PLMN);
617 ngm = (struct gsm322_msg *) nmsg->data;
620 gsm322_plmn_sendmsg(ms, nmsg);
625 DEFUN(call, call_cmd, "call MS_NAME (NUMBER|emergency|answer|hangup|hold)",
626 "Make a call\nName of MS (see \"show ms\")\nPhone number to call "
627 "(Use digits '0123456789*#abc', and '+' to dial international)\n"
628 "Make an emergency call\nAnswer an incomming call\nHangup a call\n"
629 "Hold current active call\n")
631 struct osmocom_ms *ms;
634 ms = get_ms(argv[0], vty);
638 if (!strcmp(argv[1], "emergency"))
639 mncc_call(ms, (char *)argv[1]);
640 else switch (argv[1][0]) {
645 if (argv[1][1] == 'a')
651 for (i = 0; i < strlen(argv[1]); i++) {
652 /* allow international notation with + */
653 if (i == 0 && argv[1][i] == '+')
655 if (!(argv[1][i] >= '0' && argv[1][i] <= '9')
658 && !(argv[1][i] >= 'a' && argv[1][i] <= 'c')) {
659 vty_out(vty, "Invalid digit '%c'%s", argv[1][i],
664 mncc_call(ms, (char *)argv[1]);
670 DEFUN(call_retr, call_retr_cmd, "call MS_NAME retrieve [number]",
671 "Make a call\nName of MS (see \"show ms\")\n"
672 "Retrieve call on hold\nNumber of call to retrieve")
674 struct osmocom_ms *ms;
676 ms = get_ms(argv[0], vty);
680 mncc_retrieve(ms, (argc > 1) ? atoi(argv[1]) : 0);
685 DEFUN(network_show, network_show_cmd, "network show MS_NAME",
686 "Network ...\nShow results of network search (again)\n"
687 "Name of MS (see \"show ms\")")
689 struct osmocom_ms *ms;
690 struct gsm_settings *set;
691 struct gsm322_plmn *plmn;
692 struct gsm322_plmn_list *temp;
694 ms = get_ms(argv[0], vty);
700 if (set->plmn_mode != PLMN_MODE_AUTO
701 && plmn->state != GSM322_M3_NOT_ON_PLMN) {
702 vty_out(vty, "Start network search first!%s", VTY_NEWLINE);
706 llist_for_each_entry(temp, &plmn->sorted_plmn, entry)
707 vty_out(vty, " Network %s, %s (%s, %s)%s",
708 gsm_print_mcc(temp->mcc), gsm_print_mnc(temp->mnc),
709 gsm_get_mcc(temp->mcc),
710 gsm_get_mnc(temp->mcc, temp->mnc), VTY_NEWLINE);
715 DEFUN(network_search, network_search_cmd, "network search MS_NAME",
716 "Network ...\nTrigger network search\nName of MS (see \"show ms\")")
718 struct osmocom_ms *ms;
721 ms = get_ms(argv[0], vty);
725 nmsg = gsm322_msgb_alloc(GSM322_EVENT_USER_RESEL);
728 gsm322_plmn_sendmsg(ms, nmsg);
733 DEFUN(cfg_gps_enable, cfg_gps_enable_cmd, "gps enable",
738 vty_out(vty, "Failed to open GPS device!%s", VTY_NEWLINE);
746 DEFUN(cfg_no_gps_enable, cfg_no_gps_enable_cmd, "no gps enable",
747 NO_STR "Disable GPS receiver")
756 DEFUN(cfg_gps_device, cfg_gps_device_cmd, "gps device DEVICE",
757 "GPS receiver\nSelect serial device\n"
758 "Full path of serial device including /dev/")
760 strncpy(gps.device, argv[0], sizeof(gps.device));
761 gps.device[sizeof(gps.device) - 1] = '\0';
765 vty_out(vty, "Failed to open GPS device!%s",
774 DEFUN(cfg_gps_baud, cfg_gps_baud_cmd, "gps baudrate "
775 "(default|4800|""9600|19200|38400|57600|115200)",
776 "GPS receiver\nSelect baud rate\nDefault, don't modify\n\n\n\n\n\n")
778 if (argv[0][0] == 'd')
781 gps.baud = atoi(argv[0]);
786 vty_out(vty, "Failed to open GPS device!%s",
796 DEFUN(cfg_ms, cfg_ms_cmd, "ms MS_NAME",
797 "Select a mobile station to configure\nName of MS (see \"show ms\")")
799 struct osmocom_ms *ms;
801 ms = get_ms(argv[0], vty);
811 #define SUP_WRITE(item, cmd) \
813 vty_out(vty, " %s%s%s", (set->item) ? "" : "no ", cmd, \
816 static void config_write_ms_single(struct vty *vty, struct osmocom_ms *ms)
818 struct gsm_settings *set = &ms->settings;
819 struct gsm_support *sup = &ms->support;
821 vty_out(vty, "ms %s%s", ms->name, VTY_NEWLINE);
822 switch(set->sim_type) {
823 case GSM_SIM_TYPE_NONE:
824 vty_out(vty, " sim none%s", VTY_NEWLINE);
826 case GSM_SIM_TYPE_READER:
827 vty_out(vty, " sim reader%s", VTY_NEWLINE);
829 case GSM_SIM_TYPE_TEST:
830 vty_out(vty, " sim test%s", VTY_NEWLINE);
833 vty_out(vty, " network-selection-mode %s%s", (set->plmn_mode
834 == PLMN_MODE_AUTO) ? "auto" : "manual", VTY_NEWLINE);
835 vty_out(vty, " imei %s %s%s", set->imei,
836 set->imeisv + strlen(set->imei), VTY_NEWLINE);
837 if (set->imei_random)
838 vty_out(vty, " imei-random %d%s", set->imei_random,
841 vty_out(vty, " imei-fixed%s", VTY_NEWLINE);
842 if (set->emergency_imsi[0])
843 vty_out(vty, " emergency-imsi %s%s", set->emergency_imsi,
846 vty_out(vty, " no emergency-imsi%s", VTY_NEWLINE);
847 vty_out(vty, " %scall-waiting%s", (set->cw) ? "" : "no ", VTY_NEWLINE);
848 vty_out(vty, " %sclip%s", (set->clip) ? "" : "no ", VTY_NEWLINE);
849 vty_out(vty, " %sclir%s", (set->clir) ? "" : "no ", VTY_NEWLINE);
850 if (set->alter_tx_power)
851 if (set->alter_tx_power_value)
852 vty_out(vty, " tx-power %d%s",
853 set->alter_tx_power_value, VTY_NEWLINE);
855 vty_out(vty, " tx-power full%s", VTY_NEWLINE);
857 vty_out(vty, " tx-power auto%s", VTY_NEWLINE);
858 if (set->alter_delay)
859 vty_out(vty, " simulated-delay %d%s", set->alter_delay,
862 vty_out(vty, " no simulated-delay%s", VTY_NEWLINE);
864 vty_out(vty, " stick %d%s", set->stick_arfcn,
867 vty_out(vty, " no stick%s", VTY_NEWLINE);
869 vty_out(vty, " no location-updating%s", VTY_NEWLINE);
871 vty_out(vty, " location-updating%s", VTY_NEWLINE);
872 if (set->full_v1 || set->full_v2 || set->full_v3) {
873 /* mandatory anyway */
874 vty_out(vty, " codec full-speed%s%s",
875 (!set->half_prefer) ? " prefer" : "",
878 if (set->half_v1 || set->half_v3) {
880 vty_out(vty, " codec half-speed%s%s",
881 (set->half_prefer) ? " prefer" : "",
884 vty_out(vty, " no codec half-speed%s", VTY_NEWLINE);
886 vty_out(vty, " support%s", VTY_NEWLINE);
887 SUP_WRITE(sms_ptp, "sms");
888 SUP_WRITE(a5_1, "a5/1");
889 SUP_WRITE(a5_2, "a5/2");
890 SUP_WRITE(a5_3, "a5/3");
891 SUP_WRITE(a5_4, "a5/4");
892 SUP_WRITE(a5_5, "a5/5");
893 SUP_WRITE(a5_6, "a5/6");
894 SUP_WRITE(a5_7, "a5/7");
895 SUP_WRITE(p_gsm, "p-gsm");
896 SUP_WRITE(e_gsm, "e-gsm");
897 SUP_WRITE(r_gsm, "r-gsm");
898 SUP_WRITE(dcs, "dcs");
899 vty_out(vty, " class-900 %d%s", set->class_900, VTY_NEWLINE);
900 vty_out(vty, " class-dcs %d%s", set->class_dcs, VTY_NEWLINE);
901 switch (set->ch_cap) {
903 vty_out(vty, " channel-capability sdcch%s", VTY_NEWLINE);
905 case GSM_CAP_SDCCH_TCHF:
906 vty_out(vty, " channel-capability sdcch+tchf%s", VTY_NEWLINE);
908 case GSM_CAP_SDCCH_TCHF_TCHH:
909 vty_out(vty, " channel-capability sdcch+tchf+tchh%s",
913 SUP_WRITE(full_v1, "full-speech-v1");
914 SUP_WRITE(full_v2, "full-speech-v2");
915 SUP_WRITE(full_v3, "full-speech-v3");
916 SUP_WRITE(half_v1, "half-speech-v1");
917 SUP_WRITE(half_v3, "half-speech-v3");
918 vty_out(vty, " min-rxlev %d%s", set->min_rxlev_db, VTY_NEWLINE);
919 vty_out(vty, " dsc-max %d%s", set->dsc_max, VTY_NEWLINE);
920 vty_out(vty, " exit%s", VTY_NEWLINE);
921 vty_out(vty, " test-sim%s", VTY_NEWLINE);
922 vty_out(vty, " imsi %s%s", set->test_imsi, VTY_NEWLINE);
923 switch (set->test_ki_type) {
924 case GSM_SIM_KEY_XOR:
925 vty_out(vty, " ki xor %s%s", hexdump(set->test_ki, 12),
928 case GSM_SIM_KEY_COMP128:
929 vty_out(vty, " ki comp128 %s%s", hexdump(set->test_ki, 16),
933 vty_out(vty, " %sbarred-access%s", (set->test_barr) ? "" : "no ",
935 if (set->test_rplmn_valid)
936 vty_out(vty, " rplmn %s %s%s",
937 gsm_print_mcc(set->test_rplmn_mcc),
938 gsm_print_mnc(set->test_rplmn_mnc),
941 vty_out(vty, " no rplmn%s", VTY_NEWLINE);
942 vty_out(vty, " hplmn-search %s%s", (set->test_always) ? "everywhere"
943 : "foreign-country", VTY_NEWLINE);
944 vty_out(vty, " exit%s", VTY_NEWLINE);
945 vty_out(vty, "exit%s", VTY_NEWLINE);
946 vty_out(vty, "!%s", VTY_NEWLINE);
949 static int config_write_ms(struct vty *vty)
951 struct osmocom_ms *ms;
953 vty_out(vty, "gps device %s%s", gps.device, VTY_NEWLINE);
955 vty_out(vty, "gps baudrate %d%s", gps.baud, VTY_NEWLINE);
957 vty_out(vty, "gps baudrate default%s", VTY_NEWLINE);
958 vty_out(vty, "%sgps enable%s", (gps.enable) ? "" : "no ", VTY_NEWLINE);
959 vty_out(vty, "!%s", VTY_NEWLINE);
961 llist_for_each_entry(ms, &ms_list, entity)
962 config_write_ms_single(vty, ms);
967 DEFUN(cfg_ms_sim, cfg_ms_sim_cmd, "sim (none|reader|test)",
968 "Set SIM card type when powering on\nNo SIM interted\n"
969 "Use SIM from reader\nTest SIM inserted")
971 struct osmocom_ms *ms = vty->index;
972 struct gsm_settings *set = &ms->settings;
974 switch (argv[0][0]) {
976 set->sim_type = GSM_SIM_TYPE_NONE;
979 set->sim_type = GSM_SIM_TYPE_READER;
982 set->sim_type = GSM_SIM_TYPE_TEST;
985 vty_out(vty, "unknown SIM type%s", VTY_NEWLINE);
993 DEFUN(cfg_ms_mode, cfg_ms_mode_cmd, "network-selection-mode (auto|manual)",
994 "Set network selection mode\nAutomatic network selection\n"
995 "Manual network selection")
997 struct osmocom_ms *ms = vty->index;
998 struct gsm_settings *set = &ms->settings;
1001 if (!ms->plmn.state) {
1002 if (argv[0][0] == 'a')
1003 set->plmn_mode = PLMN_MODE_AUTO;
1005 set->plmn_mode = PLMN_MODE_MANUAL;
1009 if (argv[0][0] == 'a')
1010 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SEL_AUTO);
1012 nmsg = gsm322_msgb_alloc(GSM322_EVENT_SEL_MANUAL);
1015 gsm322_plmn_sendmsg(ms, nmsg);
1020 DEFUN(cfg_ms_imei, cfg_ms_imei_cmd, "imei IMEI [SV]",
1021 "Set IMEI (enter without control digit)\n15 Digits IMEI\n"
1022 "Software version digit")
1024 struct osmocom_ms *ms = vty->index;
1025 struct gsm_settings *set = &ms->settings;
1026 char *error, *sv = "0";
1029 sv = (char *)argv[1];
1031 error = gsm_check_imei(argv[0], sv);
1033 vty_out(vty, "%s%s", error, VTY_NEWLINE);
1037 strcpy(set->imei, argv[0]);
1038 strcpy(set->imeisv, argv[0]);
1039 strcpy(set->imeisv + 15, sv);
1044 DEFUN(cfg_ms_imei_fixed, cfg_ms_imei_fixed_cmd, "imei-fixed",
1045 "Use fixed IMEI on every power on")
1047 struct osmocom_ms *ms = vty->index;
1048 struct gsm_settings *set = &ms->settings;
1050 set->imei_random = 0;
1056 DEFUN(cfg_ms_imei_random, cfg_ms_imei_random_cmd, "imei-random <0-15>",
1057 "Use random IMEI on every power on\n"
1058 "Number of trailing digits to randomize")
1060 struct osmocom_ms *ms = vty->index;
1061 struct gsm_settings *set = &ms->settings;
1063 set->imei_random = atoi(argv[0]);
1069 DEFUN(cfg_ms_emerg_imsi, cfg_ms_emerg_imsi_cmd, "emergency-imsi IMSI",
1070 "Use special IMSI for emergency calls\n15 digits IMSI")
1072 struct osmocom_ms *ms = vty->index;
1073 struct gsm_settings *set = &ms->settings;
1076 error = gsm_check_imsi(argv[0]);
1078 vty_out(vty, "%s%s", error, VTY_NEWLINE);
1081 strcpy(set->emergency_imsi, argv[0]);
1086 DEFUN(cfg_ms_no_emerg_imsi, cfg_ms_no_emerg_imsi_cmd, "no emergency-imsi",
1087 NO_STR "Use IMSI of SIM or IMEI for emergency calls")
1089 struct osmocom_ms *ms = vty->index;
1090 struct gsm_settings *set = &ms->settings;
1092 set->emergency_imsi[0] = '\0';
1097 DEFUN(cfg_no_cw, cfg_ms_no_cw_cmd, "no call-waiting",
1098 NO_STR "Disallow waiting calls")
1100 struct osmocom_ms *ms = vty->index;
1101 struct gsm_settings *set = &ms->settings;
1108 DEFUN(cfg_cw, cfg_ms_cw_cmd, "call-waiting",
1109 "Allow waiting calls")
1111 struct osmocom_ms *ms = vty->index;
1112 struct gsm_settings *set = &ms->settings;
1119 DEFUN(cfg_clip, cfg_ms_clip_cmd, "clip",
1120 "Force caller ID presentation")
1122 struct osmocom_ms *ms = vty->index;
1123 struct gsm_settings *set = &ms->settings;
1131 DEFUN(cfg_clir, cfg_ms_clir_cmd, "clir",
1132 "Force caller ID restriction")
1134 struct osmocom_ms *ms = vty->index;
1135 struct gsm_settings *set = &ms->settings;
1143 DEFUN(cfg_no_clip, cfg_ms_no_clip_cmd, "no clip",
1144 NO_STR "Disable forcing of caller ID presentation")
1146 struct osmocom_ms *ms = vty->index;
1147 struct gsm_settings *set = &ms->settings;
1154 DEFUN(cfg_no_clir, cfg_ms_no_clir_cmd, "no clir",
1155 NO_STR "Disable forcing of caller ID restriction")
1157 struct osmocom_ms *ms = vty->index;
1158 struct gsm_settings *set = &ms->settings;
1165 DEFUN(cfg_ms_tx_power, cfg_ms_tx_power_cmd, "tx-power (auto|full)",
1166 "Set the way to choose transmit power\nControlled by BTS\n"
1167 "Always full power\nFixed GSM power value if supported")
1169 struct osmocom_ms *ms = vty->index;
1170 struct gsm_settings *set = &ms->settings;
1172 switch (argv[0][0]) {
1174 set->alter_tx_power = 0;
1177 set->alter_tx_power = 1;
1178 set->alter_tx_power_value = 0;
1185 DEFUN(cfg_ms_tx_power_val, cfg_ms_tx_power_val_cmd, "tx-power <0-31>",
1186 "Set the way to choose transmit power\n"
1187 "Fixed GSM power value if supported")
1189 struct osmocom_ms *ms = vty->index;
1190 struct gsm_settings *set = &ms->settings;
1192 set->alter_tx_power = 1;
1193 set->alter_tx_power_value = atoi(argv[0]);
1198 DEFUN(cfg_ms_sim_delay, cfg_ms_sim_delay_cmd, "simulated-delay <-128-127>",
1199 "Simulate a lower or higher distance from the BTS\n"
1200 "Delay in half bits (distance in 553.85 meter steps)")
1202 struct osmocom_ms *ms = vty->index;
1203 struct gsm_settings *set = &ms->settings;
1205 set->alter_delay = atoi(argv[0]);
1206 gsm48_rr_alter_delay(ms);
1211 DEFUN(cfg_ms_no_sim_delay, cfg_ms_no_sim_delay_cmd, "no simulated-delay",
1212 NO_STR "Do not simulate a lower or higher distance from the BTS")
1214 struct osmocom_ms *ms = vty->index;
1215 struct gsm_settings *set = &ms->settings;
1217 set->alter_delay = 0;
1218 gsm48_rr_alter_delay(ms);
1223 DEFUN(cfg_ms_stick, cfg_ms_stick_cmd, "stick <0-1023>",
1224 "Stick to the given cell\nARFCN of the cell to stick to")
1226 struct osmocom_ms *ms = vty->index;
1227 struct gsm_settings *set = &ms->settings;
1230 set->stick_arfcn = atoi(argv[0]);
1235 DEFUN(cfg_ms_no_stick, cfg_ms_no_stick_cmd, "no stick",
1236 NO_STR "Do not stick to any cell")
1238 struct osmocom_ms *ms = vty->index;
1239 struct gsm_settings *set = &ms->settings;
1246 DEFUN(cfg_ms_lupd, cfg_ms_lupd_cmd, "location-updating",
1247 "Allow location updating")
1249 struct osmocom_ms *ms = vty->index;
1250 struct gsm_settings *set = &ms->settings;
1257 DEFUN(cfg_ms_no_lupd, cfg_ms_no_lupd_cmd, "no location-updating",
1258 NO_STR "Do not allow location updating")
1260 struct osmocom_ms *ms = vty->index;
1261 struct gsm_settings *set = &ms->settings;
1268 DEFUN(cfg_codec_full, cfg_ms_codec_full_cmd, "codec full-speed",
1269 "Enable codec\nFull speed speech codec")
1271 struct osmocom_ms *ms = vty->index;
1272 struct gsm_settings *set = &ms->settings;
1274 if (!set->full_v1 && !set->full_v2 && !set->full_v3) {
1275 vty_out(vty, "Full-rate codec not supported%s", VTY_NEWLINE);
1282 DEFUN(cfg_codec_full_pref, cfg_ms_codec_full_pref_cmd, "codec full-speed "
1284 "Enable codec\nFull speed speech codec\nPrefer this codec")
1286 struct osmocom_ms *ms = vty->index;
1287 struct gsm_settings *set = &ms->settings;
1289 if (!set->full_v1 && !set->full_v2 && !set->full_v3) {
1290 vty_out(vty, "Full-rate codec not supported%s", VTY_NEWLINE);
1294 set->half_prefer = 0;
1299 DEFUN(cfg_codec_half, cfg_ms_codec_half_cmd, "codec half-speed",
1300 "Enable codec\nHalf speed speech codec")
1302 struct osmocom_ms *ms = vty->index;
1303 struct gsm_settings *set = &ms->settings;
1305 if (!set->half_v1 && !set->half_v3) {
1306 vty_out(vty, "Half-rate codec not supported%s", VTY_NEWLINE);
1315 DEFUN(cfg_codec_half_pref, cfg_ms_codec_half_pref_cmd, "codec half-speed "
1317 "Enable codec\nHalf speed speech codec\nPrefer this codec")
1319 struct osmocom_ms *ms = vty->index;
1320 struct gsm_settings *set = &ms->settings;
1322 if (!set->half_v1 && !set->half_v3) {
1323 vty_out(vty, "Half-rate codec not supported%s", VTY_NEWLINE);
1328 set->half_prefer = 1;
1333 DEFUN(cfg_no_codec_half, cfg_ms_no_codec_half_cmd, "no codec half-speed",
1334 NO_STR "Disable codec\nHalf speed speech codec")
1336 struct osmocom_ms *ms = vty->index;
1337 struct gsm_settings *set = &ms->settings;
1339 if (!set->half_v1 && !set->half_v3) {
1340 vty_out(vty, "Half-rate codec not supported%s", VTY_NEWLINE);
1345 set->half_prefer = 0;
1350 static int config_write_dummy(struct vty *vty)
1355 /* per support config */
1356 DEFUN(cfg_ms_support, cfg_ms_support_cmd, "support",
1357 "Define supported features")
1359 vty->node = SUPPORT_NODE;
1364 #define SUP_EN(cfg, cfg_cmd, item, cmd, desc, restart) \
1365 DEFUN(cfg, cfg_cmd, cmd, "Enable " desc "support") \
1367 struct osmocom_ms *ms = vty->index; \
1368 struct gsm_settings *set = &ms->settings; \
1369 struct gsm_support *sup = &ms->support; \
1371 vty_out(vty, desc " not supported%s", VTY_NEWLINE); \
1373 return CMD_SUCCESS; \
1374 return CMD_WARNING; \
1379 return CMD_SUCCESS; \
1382 #define SUP_DI(cfg, cfg_cmd, item, cmd, desc, restart) \
1383 DEFUN(cfg, cfg_cmd, "no " cmd, NO_STR "Disable " desc " support") \
1385 struct osmocom_ms *ms = vty->index; \
1386 struct gsm_settings *set = &ms->settings; \
1387 struct gsm_support *sup = &ms->support; \
1389 vty_out(vty, desc " not supported%s", VTY_NEWLINE); \
1391 return CMD_SUCCESS; \
1392 return CMD_WARNING; \
1397 return CMD_SUCCESS; \
1400 SUP_EN(cfg_ms_sup_sms, cfg_ms_sup_sms_cmd, sms_ptp, "sms", "SMS", 0);
1401 SUP_DI(cfg_ms_sup_no_sms, cfg_ms_sup_no_sms_cmd, sms_ptp, "sms", "SMS", 0);
1402 SUP_EN(cfg_ms_sup_a5_1, cfg_ms_sup_a5_1_cmd, a5_1, "a5/1", "A5/1", 0);
1403 SUP_DI(cfg_ms_sup_no_a5_1, cfg_ms_sup_no_a5_1_cmd, a5_1, "a5/1", "A5/1", 0);
1404 SUP_EN(cfg_ms_sup_a5_2, cfg_ms_sup_a5_2_cmd, a5_2, "a5/2", "A5/2", 0);
1405 SUP_DI(cfg_ms_sup_no_a5_2, cfg_ms_sup_no_a5_2_cmd, a5_2, "a5/2", "A5/2", 0);
1406 SUP_EN(cfg_ms_sup_a5_3, cfg_ms_sup_a5_3_cmd, a5_3, "a5/3", "A5/3", 0);
1407 SUP_DI(cfg_ms_sup_no_a5_3, cfg_ms_sup_no_a5_3_cmd, a5_3, "a5/3", "A5/3", 0);
1408 SUP_EN(cfg_ms_sup_a5_4, cfg_ms_sup_a5_4_cmd, a5_4, "a5/4", "A5/4", 0);
1409 SUP_DI(cfg_ms_sup_no_a5_4, cfg_ms_sup_no_a5_4_cmd, a5_4, "a5/4", "A5/4", 0);
1410 SUP_EN(cfg_ms_sup_a5_5, cfg_ms_sup_a5_5_cmd, a5_5, "a5/5", "A5/5", 0);
1411 SUP_DI(cfg_ms_sup_no_a5_5, cfg_ms_sup_no_a5_5_cmd, a5_5, "a5/5", "A5/5", 0);
1412 SUP_EN(cfg_ms_sup_a5_6, cfg_ms_sup_a5_6_cmd, a5_6, "a5/6", "A5/6", 0);
1413 SUP_DI(cfg_ms_sup_no_a5_6, cfg_ms_sup_no_a5_6_cmd, a5_6, "a5/6", "A5/6", 0);
1414 SUP_EN(cfg_ms_sup_a5_7, cfg_ms_sup_a5_7_cmd, a5_7, "a5/7", "A5/7", 0);
1415 SUP_DI(cfg_ms_sup_no_a5_7, cfg_ms_sup_no_a5_7_cmd, a5_7, "a5/7", "A5/7", 1);
1416 SUP_EN(cfg_ms_sup_p_gsm, cfg_ms_sup_p_gsm_cmd, p_gsm, "p-gsm", "P-GSM (900)",
1418 SUP_DI(cfg_ms_sup_no_p_gsm, cfg_ms_sup_no_p_gsm_cmd, p_gsm, "p-gsm",
1420 SUP_EN(cfg_ms_sup_e_gsm, cfg_ms_sup_e_gsm_cmd, e_gsm, "e-gsm", "E-GSM (850)",
1422 SUP_DI(cfg_ms_sup_no_e_gsm, cfg_ms_sup_no_e_gsm_cmd, e_gsm, "e-gsm",
1424 SUP_EN(cfg_ms_sup_r_gsm, cfg_ms_sup_r_gsm_cmd, r_gsm, "r-gsm", "R-GSM (850)",
1426 SUP_DI(cfg_ms_sup_no_r_gsm, cfg_ms_sup_no_r_gsm_cmd, r_gsm, "r-gsm",
1428 SUP_EN(cfg_ms_sup_dcs, cfg_ms_sup_dcs_cmd, dcs, "dcs", "DCS (1800)", 0);
1429 SUP_DI(cfg_ms_sup_no_dcs, cfg_ms_sup_no_dcs_cmd, dcs, "dcs", "DCS (1800)", 0);
1431 DEFUN(cfg_ms_sup_class_900, cfg_ms_sup_class_900_cmd, "class-900 (1|2|3|4|5)",
1432 "Select power class for GSM 850/900\n"
1439 struct osmocom_ms *ms = vty->index;
1440 struct gsm_settings *set = &ms->settings;
1441 struct gsm_support *sup = &ms->support;
1443 set->class_900 = atoi(argv[0]);
1445 if (set->class_900 < sup->class_900 && !vty_reading)
1446 vty_out(vty, "You selected an higher class than supported "
1447 " by hardware!%s", VTY_NEWLINE);
1452 DEFUN(cfg_ms_sup_class_dcs, cfg_ms_sup_class_dcs_cmd, "class-dcs (1|2|3)",
1453 "Select power class for DCS 1800\n"
1458 struct osmocom_ms *ms = vty->index;
1459 struct gsm_settings *set = &ms->settings;
1460 struct gsm_support *sup = &ms->support;
1462 set->class_dcs = atoi(argv[0]);
1464 if (((set->class_dcs + 1) & 3) < ((sup->class_dcs + 1) & 3)
1466 vty_out(vty, "You selected an higher class than supported "
1467 " by hardware!%s", VTY_NEWLINE);
1472 DEFUN(cfg_ms_sup_ch_cap, cfg_ms_sup_ch_cap_cmd, "channel-capability "
1473 "(sdcch|sdcch+tchf|sdcch+tchf+tchh)",
1474 "Select channel capability\nSDCCH only\nSDCCH + TCH/F\nSDCCH + TCH/H")
1476 struct osmocom_ms *ms = vty->index;
1477 struct gsm_settings *set = &ms->settings;
1478 struct gsm_support *sup = &ms->support;
1481 if (!strcmp(argv[0], "sdcch+tchf+tchh"))
1482 ch_cap = GSM_CAP_SDCCH_TCHF_TCHH;
1483 else if (!strcmp(argv[0], "sdcch+tchf"))
1484 ch_cap = GSM_CAP_SDCCH_TCHF;
1486 ch_cap = GSM_CAP_SDCCH;
1488 if (ch_cap > sup->ch_cap && !vty_reading) {
1489 vty_out(vty, "You selected an higher capability than supported "
1490 " by hardware!%s", VTY_NEWLINE);
1494 set->ch_cap = ch_cap;
1499 SUP_EN(cfg_ms_sup_full_v1, cfg_ms_sup_full_v1_cmd, full_v1, "full-speech-v1",
1500 "Full rate speech V1", 0);
1501 SUP_DI(cfg_ms_sup_no_full_v1, cfg_ms_sup_no_full_v1_cmd, full_v1,
1502 "full-speech-v1", "Full rate speech V1", 0);
1503 SUP_EN(cfg_ms_sup_full_v2, cfg_ms_sup_full_v2_cmd, full_v2, "full-speech-v2",
1504 "Full rate speech V2 (EFR)", 0);
1505 SUP_DI(cfg_ms_sup_no_full_v2, cfg_ms_sup_no_full_v2_cmd, full_v2,
1506 "full-speech-v2", "Full rate speech V2 (EFR)", 0);
1507 SUP_EN(cfg_ms_sup_full_v3, cfg_ms_sup_full_v3_cmd, full_v3, "full-speech-v3",
1508 "Full rate speech V3 (AMR)", 0);
1509 SUP_DI(cfg_ms_sup_no_full_v3, cfg_ms_sup_no_full_v3_cmd, full_v3,
1510 "full-speech-v3", "Full rate speech V3 (AMR)", 0);
1511 SUP_EN(cfg_ms_sup_half_v1, cfg_ms_sup_half_v1_cmd, half_v1, "half-speech-v1",
1512 "Half rate speech V1 (AMR)", 0);
1513 SUP_DI(cfg_ms_sup_no_half_v1, cfg_ms_sup_no_half_v1_cmd, half_v1,
1514 "half-speech-v1", "Half rate speech V1", 0);
1515 SUP_EN(cfg_ms_sup_half_v3, cfg_ms_sup_half_v3_cmd, half_v3, "half-speech-v3",
1516 "Half rate speech V3 (AMR)", 0);
1517 SUP_DI(cfg_ms_sup_no_half_v3, cfg_ms_sup_no_half_v3_cmd, half_v3,
1518 "half-speech-v3", "Half rate speech V3", 0);
1520 DEFUN(cfg_ms_sup_min_rxlev, cfg_ms_sup_min_rxlev_cmd, "min-rxlev <-110--47>",
1521 "Set the minimum receive level to select a cell\n"
1522 "Minimum receive level from -110 dBm to -47 dBm")
1524 struct osmocom_ms *ms = vty->index;
1525 struct gsm_settings *set = &ms->settings;
1527 set->min_rxlev_db = atoi(argv[0]);
1532 DEFUN(cfg_ms_sup_dsc_max, cfg_ms_sup_dsc_max_cmd, "dsc-max <90-500>",
1533 "Set the maximum DSC value. Standard is 90. Increase to make mobile "
1534 "more reliable against bad RX signal. This increase the propability "
1535 "of missing a paging requests\n"
1536 "DSC initial and maximum value (standard is 90)")
1538 struct osmocom_ms *ms = vty->index;
1539 struct gsm_settings *set = &ms->settings;
1541 set->dsc_max = atoi(argv[0]);
1546 /* per testsim config */
1547 DEFUN(cfg_ms_testsim, cfg_ms_testsim_cmd, "test-sim",
1548 "Configure test SIM emulation")
1550 vty->node = TESTSIM_NODE;
1555 DEFUN(cfg_test_imsi, cfg_test_imsi_cmd, "imsi IMSI",
1556 "Set IMSI on test card\n15 digits IMSI")
1558 struct osmocom_ms *ms = vty->index;
1559 struct gsm_settings *set = &ms->settings;
1560 char *error = gsm_check_imsi(argv[0]);
1563 vty_out(vty, "%s%s", error, VTY_NEWLINE);
1567 strcpy(set->test_imsi, argv[0]);
1573 #define HEX_STR "\nByte as two digits hexadecimal"
1574 DEFUN(cfg_test_ki_xor, cfg_test_ki_xor_cmd, "ki xor HEX HEX HEX HEX HEX HEX "
1575 "HEX HEX HEX HEX HEX HEX",
1576 "Set Key (Kc) on test card\nUse XOR algorithm" HEX_STR HEX_STR HEX_STR
1577 HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR)
1579 struct osmocom_ms *ms = vty->index;
1580 struct gsm_settings *set = &ms->settings;
1585 for (i = 0; i < 12; i++) {
1587 if (!strncmp(p, "0x", 2))
1589 if (strlen(p) != 2) {
1590 vty_out(vty, "Expecting two digits hex value (with or "
1591 "without 0x in front)%s", VTY_NEWLINE);
1594 ki[i] = strtoul(p, NULL, 16);
1597 set->test_ki_type = GSM_SIM_KEY_XOR;
1598 memcpy(set->test_ki, ki, 12);
1602 DEFUN(cfg_test_ki_comp128, cfg_test_ki_comp128_cmd, "ki comp128 HEX HEX HEX "
1603 "HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX HEX",
1604 "Set Key (Kc) on test card\nUse XOR algorithm" HEX_STR HEX_STR HEX_STR
1605 HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR HEX_STR
1606 HEX_STR HEX_STR HEX_STR HEX_STR)
1608 struct osmocom_ms *ms = vty->index;
1609 struct gsm_settings *set = &ms->settings;
1614 for (i = 0; i < 16; i++) {
1616 if (!strncmp(p, "0x", 2))
1618 if (strlen(p) != 2) {
1619 vty_out(vty, "Expecting two digits hex value (with or "
1620 "without 0x in front)%s", VTY_NEWLINE);
1623 ki[i] = strtoul(p, NULL, 16);
1626 set->test_ki_type = GSM_SIM_KEY_COMP128;
1627 memcpy(set->test_ki, ki, 16);
1631 DEFUN(cfg_test_barr, cfg_test_barr_cmd, "barred-access",
1632 "Allow access to barred cells")
1634 struct osmocom_ms *ms = vty->index;
1635 struct gsm_settings *set = &ms->settings;
1642 DEFUN(cfg_test_no_barr, cfg_test_no_barr_cmd, "no barred-access",
1643 NO_STR "Deny access to barred cells")
1645 struct osmocom_ms *ms = vty->index;
1646 struct gsm_settings *set = &ms->settings;
1653 DEFUN(cfg_test_no_rplmn, cfg_test_no_rplmn_cmd, "no rplmn",
1654 NO_STR "Unset Registered PLMN")
1656 struct osmocom_ms *ms = vty->index;
1657 struct gsm_settings *set = &ms->settings;
1659 set->test_rplmn_valid = 0;
1665 DEFUN(cfg_test_rplmn, cfg_test_rplmn_cmd, "rplmn MCC MNC",
1666 "Set Registered PLMN\nMobile Country Code\nMobile Network Code")
1668 struct osmocom_ms *ms = vty->index;
1669 struct gsm_settings *set = &ms->settings;
1670 uint16_t mcc = gsm_input_mcc((char *)argv[0]),
1671 mnc = gsm_input_mnc((char *)argv[1]);
1674 vty_out(vty, "Given MCC invalid%s", VTY_NEWLINE);
1678 vty_out(vty, "Given MNC invalid%s", VTY_NEWLINE);
1681 set->test_rplmn_valid = 1;
1682 set->test_rplmn_mcc = mcc;
1683 set->test_rplmn_mnc = mnc;
1689 DEFUN(cfg_test_hplmn, cfg_test_hplmn_cmd, "hplmn-search (everywhere|foreign-country)",
1690 "Set Home PLMN search mode\n"
1691 "Search for HPLMN when on any other network\n"
1692 "Search for HPLMN when in a different country")
1694 struct osmocom_ms *ms = vty->index;
1695 struct gsm_settings *set = &ms->settings;
1697 switch (argv[0][0]) {
1699 set->test_always = 1;
1702 set->test_always = 0;
1710 enum node_type ms_vty_go_parent(struct vty *vty)
1712 switch (vty->node) {
1714 vty->node = CONFIG_NODE;
1719 vty->node = MS_NODE;
1722 vty->node = CONFIG_NODE;
1728 /* Down vty node level. */
1729 gDEFUN(ournode_exit,
1730 ournode_exit_cmd, "exit", "Exit current mode and down to previous mode\n")
1732 switch (vty->node) {
1734 vty->node = CONFIG_NODE;
1739 vty->node = MS_NODE;
1747 /* End of configuration. */
1749 ournode_end_cmd, "end", "End current mode and change to enable mode.")
1751 switch (vty->node) {
1754 /* Nothing to do. */
1761 vty_config_unlock(vty);
1762 vty->node = ENABLE_NODE;
1764 vty->index_sub = NULL;
1772 #define SUP_NODE(item) \
1773 install_element(SUPPORT_NODE, &cfg_ms_sup_item_cmd);
1775 int ms_vty_init(void)
1777 install_element_ve(&show_ms_cmd);
1778 install_element_ve(&show_subscr_cmd);
1779 install_element_ve(&show_support_cmd);
1780 install_element_ve(&show_states_cmd);
1781 install_element_ve(&show_cell_cmd);
1782 install_element_ve(&show_cell_si_cmd);
1783 install_element_ve(&show_ba_cmd);
1784 install_element_ve(&show_forb_la_cmd);
1785 install_element_ve(&show_forb_plmn_cmd);
1786 install_element_ve(&monitor_network_cmd);
1787 install_element_ve(&no_monitor_network_cmd);
1789 install_element(ENABLE_NODE, &sim_test_cmd);
1790 install_element(ENABLE_NODE, &sim_reader_cmd);
1791 install_element(ENABLE_NODE, &sim_remove_cmd);
1792 install_element(ENABLE_NODE, &sim_pin_cmd);
1793 install_element(ENABLE_NODE, &sim_disable_pin_cmd);
1794 install_element(ENABLE_NODE, &sim_enable_pin_cmd);
1795 install_element(ENABLE_NODE, &sim_change_pin_cmd);
1796 install_element(ENABLE_NODE, &sim_unblock_pin_cmd);
1797 install_element(ENABLE_NODE, &sim_lai_cmd);
1798 install_element(ENABLE_NODE, &network_search_cmd);
1799 install_element(ENABLE_NODE, &network_show_cmd);
1800 install_element(ENABLE_NODE, &network_select_cmd);
1801 install_element(ENABLE_NODE, &call_cmd);
1802 install_element(ENABLE_NODE, &call_retr_cmd);
1804 install_element(CONFIG_NODE, &cfg_gps_device_cmd);
1805 install_element(CONFIG_NODE, &cfg_gps_baud_cmd);
1806 install_element(CONFIG_NODE, &cfg_gps_enable_cmd);
1807 install_element(CONFIG_NODE, &cfg_no_gps_enable_cmd);
1809 install_element(CONFIG_NODE, &cfg_ms_cmd);
1810 install_element(CONFIG_NODE, &ournode_end_cmd);
1811 install_node(&ms_node, config_write_ms);
1812 install_default(MS_NODE);
1813 install_element(MS_NODE, &ournode_exit_cmd);
1814 install_element(MS_NODE, &ournode_end_cmd);
1815 install_element(MS_NODE, &cfg_ms_sim_cmd);
1816 install_element(MS_NODE, &cfg_ms_mode_cmd);
1817 install_element(MS_NODE, &cfg_ms_imei_cmd);
1818 install_element(MS_NODE, &cfg_ms_imei_fixed_cmd);
1819 install_element(MS_NODE, &cfg_ms_imei_random_cmd);
1820 install_element(MS_NODE, &cfg_ms_no_emerg_imsi_cmd);
1821 install_element(MS_NODE, &cfg_ms_emerg_imsi_cmd);
1822 install_element(MS_NODE, &cfg_ms_cw_cmd);
1823 install_element(MS_NODE, &cfg_ms_no_cw_cmd);
1824 install_element(MS_NODE, &cfg_ms_clip_cmd);
1825 install_element(MS_NODE, &cfg_ms_clir_cmd);
1826 install_element(MS_NODE, &cfg_ms_no_clip_cmd);
1827 install_element(MS_NODE, &cfg_ms_no_clir_cmd);
1828 install_element(MS_NODE, &cfg_ms_tx_power_cmd);
1829 install_element(MS_NODE, &cfg_ms_tx_power_val_cmd);
1830 install_element(MS_NODE, &cfg_ms_sim_delay_cmd);
1831 install_element(MS_NODE, &cfg_ms_no_sim_delay_cmd);
1832 install_element(MS_NODE, &cfg_ms_stick_cmd);
1833 install_element(MS_NODE, &cfg_ms_no_stick_cmd);
1834 install_element(MS_NODE, &cfg_ms_lupd_cmd);
1835 install_element(MS_NODE, &cfg_ms_no_lupd_cmd);
1836 install_element(MS_NODE, &cfg_ms_codec_full_cmd);
1837 install_element(MS_NODE, &cfg_ms_codec_full_pref_cmd);
1838 install_element(MS_NODE, &cfg_ms_codec_half_cmd);
1839 install_element(MS_NODE, &cfg_ms_codec_half_pref_cmd);
1840 install_element(MS_NODE, &cfg_ms_no_codec_half_cmd);
1841 install_element(MS_NODE, &cfg_ms_testsim_cmd);
1842 install_element(MS_NODE, &cfg_ms_support_cmd);
1843 install_node(&support_node, config_write_dummy);
1844 install_default(SUPPORT_NODE);
1845 install_element(SUPPORT_NODE, &ournode_exit_cmd);
1846 install_element(SUPPORT_NODE, &ournode_end_cmd);
1847 install_element(SUPPORT_NODE, &cfg_ms_sup_sms_cmd);
1848 install_element(SUPPORT_NODE, &cfg_ms_sup_no_sms_cmd);
1849 install_element(SUPPORT_NODE, &cfg_ms_sup_a5_1_cmd);
1850 install_element(SUPPORT_NODE, &cfg_ms_sup_no_a5_1_cmd);
1851 install_element(SUPPORT_NODE, &cfg_ms_sup_a5_2_cmd);
1852 install_element(SUPPORT_NODE, &cfg_ms_sup_no_a5_2_cmd);
1853 install_element(SUPPORT_NODE, &cfg_ms_sup_a5_3_cmd);
1854 install_element(SUPPORT_NODE, &cfg_ms_sup_no_a5_3_cmd);
1855 install_element(SUPPORT_NODE, &cfg_ms_sup_a5_4_cmd);
1856 install_element(SUPPORT_NODE, &cfg_ms_sup_no_a5_4_cmd);
1857 install_element(SUPPORT_NODE, &cfg_ms_sup_a5_5_cmd);
1858 install_element(SUPPORT_NODE, &cfg_ms_sup_no_a5_5_cmd);
1859 install_element(SUPPORT_NODE, &cfg_ms_sup_a5_6_cmd);
1860 install_element(SUPPORT_NODE, &cfg_ms_sup_no_a5_6_cmd);
1861 install_element(SUPPORT_NODE, &cfg_ms_sup_a5_7_cmd);
1862 install_element(SUPPORT_NODE, &cfg_ms_sup_no_a5_7_cmd);
1863 install_element(SUPPORT_NODE, &cfg_ms_sup_p_gsm_cmd);
1864 install_element(SUPPORT_NODE, &cfg_ms_sup_no_p_gsm_cmd);
1865 install_element(SUPPORT_NODE, &cfg_ms_sup_e_gsm_cmd);
1866 install_element(SUPPORT_NODE, &cfg_ms_sup_no_e_gsm_cmd);
1867 install_element(SUPPORT_NODE, &cfg_ms_sup_r_gsm_cmd);
1868 install_element(SUPPORT_NODE, &cfg_ms_sup_no_r_gsm_cmd);
1869 install_element(SUPPORT_NODE, &cfg_ms_sup_dcs_cmd);
1870 install_element(SUPPORT_NODE, &cfg_ms_sup_no_dcs_cmd);
1871 install_element(SUPPORT_NODE, &cfg_ms_sup_class_900_cmd);
1872 install_element(SUPPORT_NODE, &cfg_ms_sup_class_dcs_cmd);
1873 install_element(SUPPORT_NODE, &cfg_ms_sup_ch_cap_cmd);
1874 install_element(SUPPORT_NODE, &cfg_ms_sup_full_v1_cmd);
1875 install_element(SUPPORT_NODE, &cfg_ms_sup_no_full_v1_cmd);
1876 install_element(SUPPORT_NODE, &cfg_ms_sup_full_v2_cmd);
1877 install_element(SUPPORT_NODE, &cfg_ms_sup_no_full_v2_cmd);
1878 install_element(SUPPORT_NODE, &cfg_ms_sup_full_v3_cmd);
1879 install_element(SUPPORT_NODE, &cfg_ms_sup_no_full_v3_cmd);
1880 install_element(SUPPORT_NODE, &cfg_ms_sup_half_v1_cmd);
1881 install_element(SUPPORT_NODE, &cfg_ms_sup_no_half_v1_cmd);
1882 install_element(SUPPORT_NODE, &cfg_ms_sup_half_v3_cmd);
1883 install_element(SUPPORT_NODE, &cfg_ms_sup_no_half_v3_cmd);
1884 install_element(SUPPORT_NODE, &cfg_ms_sup_min_rxlev_cmd);
1885 install_element(SUPPORT_NODE, &cfg_ms_sup_dsc_max_cmd);
1886 install_node(&testsim_node, config_write_dummy);
1887 install_default(TESTSIM_NODE);
1888 install_element(TESTSIM_NODE, &ournode_exit_cmd);
1889 install_element(TESTSIM_NODE, &ournode_end_cmd);
1890 install_element(TESTSIM_NODE, &cfg_test_imsi_cmd);
1891 install_element(TESTSIM_NODE, &cfg_test_ki_xor_cmd);
1892 install_element(TESTSIM_NODE, &cfg_test_ki_comp128_cmd);
1893 install_element(TESTSIM_NODE, &cfg_test_barr_cmd);
1894 install_element(TESTSIM_NODE, &cfg_test_no_barr_cmd);
1895 install_element(TESTSIM_NODE, &cfg_test_no_rplmn_cmd);
1896 install_element(TESTSIM_NODE, &cfg_test_rplmn_cmd);
1897 install_element(TESTSIM_NODE, &cfg_test_hplmn_cmd);
1902 void vty_notify(struct osmocom_ms *ms, const char *fmt, ...)
1904 struct telnet_connection *connection;
1910 va_start(args, fmt);
1911 vsnprintf(buffer, sizeof(buffer) - 1, fmt, args);
1912 buffer[sizeof(buffer) - 1] = '\0';
1919 llist_for_each_entry(connection, &active_connections, entry) {
1920 vty = connection->vty;
1924 vty_out(vty, "%s%% (MS %s)%s", VTY_NEWLINE, ms->name,
1928 if (buffer[strlen(buffer) - 1] == '\n') {
1929 buffer[strlen(buffer) - 1] = '\0';
1930 vty_out(vty, "%% %s%s", buffer, VTY_NEWLINE);
1931 buffer[strlen(buffer)] = '\n';
1933 vty_out(vty, "%% %s", buffer);