Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 1 | /* 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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * 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 Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 10 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * 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 Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <unistd.h> |
| 24 | #include <errno.h> |
| 25 | #include <stdint.h> |
Jacob Erlbeck | 81ffb74 | 2015-01-23 11:33:51 +0100 | [diff] [blame] | 26 | #include <time.h> |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 27 | |
| 28 | #include <arpa/inet.h> |
| 29 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 30 | #include <osmocom/core/msgb.h> |
Harald Welte | d36ff76 | 2011-03-23 18:26:56 +0100 | [diff] [blame] | 31 | #include <osmocom/gsm/tlv.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 32 | #include <osmocom/core/talloc.h> |
| 33 | #include <osmocom/core/select.h> |
| 34 | #include <osmocom/core/rate_ctr.h> |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 35 | #include <osmocom/sgsn/debug.h> |
| 36 | #include <osmocom/sgsn/signal.h> |
| 37 | #include <osmocom/sgsn/gprs_llc.h> |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 38 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 39 | #include <osmocom/vty/vty.h> |
| 40 | #include <osmocom/vty/command.h> |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 41 | |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 42 | static void vty_dump_lle(struct vty *vty, struct gprs_llc_lle *lle) |
| 43 | { |
Harald Welte | 1d9d944 | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 44 | struct gprs_llc_params *par = &lle->params; |
Pau Espin Pedrol | b0b582b | 2023-01-04 13:49:22 +0100 | [diff] [blame] | 45 | vty_out(vty, " SAPI %2u State %s VUsend=%u, VUrecv=%u", lle->sapi, |
Pau Espin Pedrol | 13c0000 | 2023-01-04 13:54:49 +0100 | [diff] [blame] | 46 | get_value_string(gprs_llc_lle_state_names, lle->state), |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 47 | lle->vu_send, lle->vu_recv); |
Harald Welte | 1d9d944 | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 48 | vty_out(vty, " Vsent=%u Vack=%u Vrecv=%u, RetransCtr=%u%s", |
| 49 | lle->v_sent, lle->v_ack, lle->v_recv, |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 50 | lle->retrans_ctr, VTY_NEWLINE); |
Harald Welte | 1d9d944 | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 51 | vty_out(vty, " T200=%u, N200=%u, N201-U=%u, N201-I=%u, mD=%u, " |
| 52 | "mU=%u, kD=%u, kU=%u%s", par->t200_201, par->n200, |
| 53 | par->n201_u, par->n201_i, par->mD, par->mU, par->kD, |
| 54 | par->kU, VTY_NEWLINE); |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Harald Welte | 1d9d944 | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 57 | static uint8_t valid_sapis[] = { 1, 2, 3, 5, 7, 8, 9, 11 }; |
| 58 | |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 59 | static void vty_dump_llme(struct vty *vty, struct gprs_llc_llme *llme) |
| 60 | { |
| 61 | unsigned int i; |
Jacob Erlbeck | 81ffb74 | 2015-01-23 11:33:51 +0100 | [diff] [blame] | 62 | struct timespec now_tp = {0}; |
Pau Espin Pedrol | 36abead | 2018-08-17 13:27:20 +0200 | [diff] [blame] | 63 | osmo_clock_gettime(CLOCK_MONOTONIC, &now_tp); |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 64 | |
Max | 549ebc7 | 2016-11-18 14:07:04 +0100 | [diff] [blame] | 65 | vty_out(vty, "TLLI %08x (Old TLLI %08x) BVCI=%u NSEI=%u %s: " |
| 66 | "IOV-UI=0x%06x CKSN=%d Age=%d: State %s%s", llme->tlli, |
| 67 | llme->old_tlli, llme->bvci, llme->nsei, |
| 68 | get_value_string(gprs_cipher_names, llme->algo), llme->iov_ui, |
| 69 | llme->cksn, llme->age_timestamp == GPRS_LLME_RESET_AGE ? 0 : |
Jacob Erlbeck | 81ffb74 | 2015-01-23 11:33:51 +0100 | [diff] [blame] | 70 | (int)(now_tp.tv_sec - (time_t)llme->age_timestamp), |
Pau Espin Pedrol | e5614e4 | 2023-01-04 13:53:57 +0100 | [diff] [blame] | 71 | get_value_string(gprs_llc_llme_state_names, llme->state), VTY_NEWLINE); |
Harald Welte | 1d9d944 | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 72 | |
| 73 | for (i = 0; i < ARRAY_SIZE(valid_sapis); i++) { |
| 74 | struct gprs_llc_lle *lle; |
| 75 | uint8_t sapi = valid_sapis[i]; |
| 76 | |
| 77 | if (sapi >= ARRAY_SIZE(llme->lle)) |
| 78 | continue; |
| 79 | |
| 80 | lle = &llme->lle[sapi]; |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 81 | vty_dump_lle(vty, lle); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 86 | DEFUN(show_llc, show_llc_cmd, |
| 87 | "show llc", |
| 88 | SHOW_STR "Display information about the LLC protocol") |
| 89 | { |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 90 | struct gprs_llc_llme *llme; |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 91 | |
| 92 | vty_out(vty, "State of LLC Entities%s", VTY_NEWLINE); |
Harald Welte | 807a5d8 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 93 | llist_for_each_entry(llme, &gprs_llc_llmes, list) { |
| 94 | vty_dump_llme(vty, llme); |
Harald Welte | 2e918a8 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 95 | } |
| 96 | return CMD_SUCCESS; |
| 97 | } |
| 98 | |
| 99 | int gprs_llc_vty_init(void) |
| 100 | { |
| 101 | install_element_ve(&show_llc_cmd); |
| 102 | |
| 103 | return 0; |
| 104 | } |