blob: bf34e9782a0c9cf41fef21b6cbaa9bceaab1df29 [file] [log] [blame]
Harald Welte2e918a82010-05-18 12:20:12 +02001/* VTY interface for our GPRS LLC implementation */
2
3/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01008 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
Harald Welte2e918a82010-05-18 12:20:12 +020010 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte2e918a82010-05-18 12:20:12 +020016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte2e918a82010-05-18 12:20:12 +020019 *
20 */
21
22#include <stdlib.h>
23#include <unistd.h>
24#include <errno.h>
25#include <stdint.h>
Jacob Erlbeck81ffb742015-01-23 11:33:51 +010026#include <time.h>
Harald Welte2e918a82010-05-18 12:20:12 +020027
28#include <arpa/inet.h>
29
30#include <openbsc/gsm_data.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010031#include <osmocom/core/msgb.h>
Harald Welted36ff762011-03-23 18:26:56 +010032#include <osmocom/gsm/tlv.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010033#include <osmocom/core/talloc.h>
34#include <osmocom/core/select.h>
35#include <osmocom/core/rate_ctr.h>
Harald Welte2e918a82010-05-18 12:20:12 +020036#include <openbsc/debug.h>
37#include <openbsc/signal.h>
38#include <openbsc/gprs_llc.h>
39
Harald Welte4b037e42010-05-19 19:45:32 +020040#include <osmocom/vty/vty.h>
41#include <osmocom/vty/command.h>
Harald Welte2e918a82010-05-18 12:20:12 +020042
43struct value_string gprs_llc_state_strs[] = {
Harald Welte807a5d82010-06-01 11:53:01 +020044 { GPRS_LLES_UNASSIGNED, "TLLI Unassigned" },
45 { GPRS_LLES_ASSIGNED_ADM, "TLLI Assigned" },
46 { GPRS_LLES_LOCAL_EST, "Local Establishment" },
47 { GPRS_LLES_REMOTE_EST, "Remote Establishment" },
48 { GPRS_LLES_ABM, "Asynchronous Balanced Mode" },
49 { GPRS_LLES_LOCAL_REL, "Local Release" },
50 { GPRS_LLES_TIMER_REC, "Timer Recovery" },
Neels Hofmeyr5616cdd2017-03-01 15:01:28 +010051 { 0, NULL }
Harald Welte2e918a82010-05-18 12:20:12 +020052};
53
54static void vty_dump_lle(struct vty *vty, struct gprs_llc_lle *lle)
55{
Harald Welte1d9d9442010-06-03 07:11:04 +020056 struct gprs_llc_params *par = &lle->params;
Harald Welte807a5d82010-06-01 11:53:01 +020057 vty_out(vty, " SAPI %2u State %s VUsend=%u, VUrecv=%u", lle->sapi,
58 get_value_string(gprs_llc_state_strs, lle->state),
59 lle->vu_send, lle->vu_recv);
Harald Welte1d9d9442010-06-03 07:11:04 +020060 vty_out(vty, " Vsent=%u Vack=%u Vrecv=%u, RetransCtr=%u%s",
61 lle->v_sent, lle->v_ack, lle->v_recv,
Harald Welte2e918a82010-05-18 12:20:12 +020062 lle->retrans_ctr, VTY_NEWLINE);
Harald Welte1d9d9442010-06-03 07:11:04 +020063 vty_out(vty, " T200=%u, N200=%u, N201-U=%u, N201-I=%u, mD=%u, "
64 "mU=%u, kD=%u, kU=%u%s", par->t200_201, par->n200,
65 par->n201_u, par->n201_i, par->mD, par->mU, par->kD,
66 par->kU, VTY_NEWLINE);
Harald Welte2e918a82010-05-18 12:20:12 +020067}
68
Harald Welte1d9d9442010-06-03 07:11:04 +020069static uint8_t valid_sapis[] = { 1, 2, 3, 5, 7, 8, 9, 11 };
70
Harald Welte807a5d82010-06-01 11:53:01 +020071static void vty_dump_llme(struct vty *vty, struct gprs_llc_llme *llme)
72{
73 unsigned int i;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +010074 struct timespec now_tp = {0};
75 clock_gettime(CLOCK_MONOTONIC, &now_tp);
Harald Welte807a5d82010-06-01 11:53:01 +020076
Max549ebc72016-11-18 14:07:04 +010077 vty_out(vty, "TLLI %08x (Old TLLI %08x) BVCI=%u NSEI=%u %s: "
78 "IOV-UI=0x%06x CKSN=%d Age=%d: State %s%s", llme->tlli,
79 llme->old_tlli, llme->bvci, llme->nsei,
80 get_value_string(gprs_cipher_names, llme->algo), llme->iov_ui,
81 llme->cksn, llme->age_timestamp == GPRS_LLME_RESET_AGE ? 0 :
Jacob Erlbeck81ffb742015-01-23 11:33:51 +010082 (int)(now_tp.tv_sec - (time_t)llme->age_timestamp),
Harald Welte807a5d82010-06-01 11:53:01 +020083 get_value_string(gprs_llc_state_strs, llme->state), VTY_NEWLINE);
Harald Welte1d9d9442010-06-03 07:11:04 +020084
85 for (i = 0; i < ARRAY_SIZE(valid_sapis); i++) {
86 struct gprs_llc_lle *lle;
87 uint8_t sapi = valid_sapis[i];
88
89 if (sapi >= ARRAY_SIZE(llme->lle))
90 continue;
91
92 lle = &llme->lle[sapi];
Harald Welte807a5d82010-06-01 11:53:01 +020093 vty_dump_lle(vty, lle);
94 }
95}
96
97
Harald Welte2e918a82010-05-18 12:20:12 +020098DEFUN(show_llc, show_llc_cmd,
99 "show llc",
100 SHOW_STR "Display information about the LLC protocol")
101{
Harald Welte807a5d82010-06-01 11:53:01 +0200102 struct gprs_llc_llme *llme;
Harald Welte2e918a82010-05-18 12:20:12 +0200103
104 vty_out(vty, "State of LLC Entities%s", VTY_NEWLINE);
Harald Welte807a5d82010-06-01 11:53:01 +0200105 llist_for_each_entry(llme, &gprs_llc_llmes, list) {
106 vty_dump_llme(vty, llme);
Harald Welte2e918a82010-05-18 12:20:12 +0200107 }
108 return CMD_SUCCESS;
109}
110
111int gprs_llc_vty_init(void)
112{
113 install_element_ve(&show_llc_cmd);
114
115 return 0;
116}