Harald Welte | 0c938b7 | 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 | 0e3e88e | 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 | 0c938b7 | 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 | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 0e3e88e | 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 | 0c938b7 | 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> |
| 26 | |
| 27 | #include <arpa/inet.h> |
| 28 | |
| 29 | #include <openbsc/gsm_data.h> |
| 30 | #include <osmocore/msgb.h> |
| 31 | #include <osmocore/tlv.h> |
| 32 | #include <osmocore/talloc.h> |
| 33 | #include <osmocore/select.h> |
| 34 | #include <osmocore/rate_ctr.h> |
| 35 | #include <openbsc/debug.h> |
| 36 | #include <openbsc/signal.h> |
| 37 | #include <openbsc/gprs_llc.h> |
| 38 | |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 39 | #include <osmocom/vty/vty.h> |
| 40 | #include <osmocom/vty/command.h> |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 41 | |
| 42 | struct value_string gprs_llc_state_strs[] = { |
Harald Welte | 75871c7 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 43 | { GPRS_LLES_UNASSIGNED, "TLLI Unassigned" }, |
| 44 | { GPRS_LLES_ASSIGNED_ADM, "TLLI Assigned" }, |
| 45 | { GPRS_LLES_LOCAL_EST, "Local Establishment" }, |
| 46 | { GPRS_LLES_REMOTE_EST, "Remote Establishment" }, |
| 47 | { GPRS_LLES_ABM, "Asynchronous Balanced Mode" }, |
| 48 | { GPRS_LLES_LOCAL_REL, "Local Release" }, |
| 49 | { GPRS_LLES_TIMER_REC, "Timer Recovery" }, |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | static void vty_dump_lle(struct vty *vty, struct gprs_llc_lle *lle) |
| 53 | { |
Harald Welte | df270ad | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 54 | struct gprs_llc_params *par = &lle->params; |
Harald Welte | 75871c7 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 55 | vty_out(vty, " SAPI %2u State %s VUsend=%u, VUrecv=%u", lle->sapi, |
| 56 | get_value_string(gprs_llc_state_strs, lle->state), |
| 57 | lle->vu_send, lle->vu_recv); |
Harald Welte | df270ad | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 58 | vty_out(vty, " Vsent=%u Vack=%u Vrecv=%u, RetransCtr=%u%s", |
| 59 | lle->v_sent, lle->v_ack, lle->v_recv, |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 60 | lle->retrans_ctr, VTY_NEWLINE); |
Harald Welte | df270ad | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 61 | vty_out(vty, " T200=%u, N200=%u, N201-U=%u, N201-I=%u, mD=%u, " |
| 62 | "mU=%u, kD=%u, kU=%u%s", par->t200_201, par->n200, |
| 63 | par->n201_u, par->n201_i, par->mD, par->mU, par->kD, |
| 64 | par->kU, VTY_NEWLINE); |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 65 | } |
| 66 | |
Harald Welte | df270ad | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 67 | static uint8_t valid_sapis[] = { 1, 2, 3, 5, 7, 8, 9, 11 }; |
| 68 | |
Harald Welte | 75871c7 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 69 | static void vty_dump_llme(struct vty *vty, struct gprs_llc_llme *llme) |
| 70 | { |
| 71 | unsigned int i; |
| 72 | |
| 73 | vty_out(vty, "TLLI %08x (Old TLLI %08x) BVCI=%u NSEI=%u: State %s%s", |
| 74 | llme->tlli, llme->old_tlli, llme->bvci, llme->nsei, |
| 75 | get_value_string(gprs_llc_state_strs, llme->state), VTY_NEWLINE); |
Harald Welte | df270ad | 2010-06-03 07:11:04 +0200 | [diff] [blame] | 76 | |
| 77 | for (i = 0; i < ARRAY_SIZE(valid_sapis); i++) { |
| 78 | struct gprs_llc_lle *lle; |
| 79 | uint8_t sapi = valid_sapis[i]; |
| 80 | |
| 81 | if (sapi >= ARRAY_SIZE(llme->lle)) |
| 82 | continue; |
| 83 | |
| 84 | lle = &llme->lle[sapi]; |
Harald Welte | 75871c7 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 85 | vty_dump_lle(vty, lle); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 90 | DEFUN(show_llc, show_llc_cmd, |
| 91 | "show llc", |
| 92 | SHOW_STR "Display information about the LLC protocol") |
| 93 | { |
Harald Welte | 75871c7 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 94 | struct gprs_llc_llme *llme; |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 95 | |
| 96 | vty_out(vty, "State of LLC Entities%s", VTY_NEWLINE); |
Harald Welte | 75871c7 | 2010-06-01 11:53:01 +0200 | [diff] [blame] | 97 | llist_for_each_entry(llme, &gprs_llc_llmes, list) { |
| 98 | vty_dump_llme(vty, llme); |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 99 | } |
| 100 | return CMD_SUCCESS; |
| 101 | } |
| 102 | |
| 103 | int gprs_llc_vty_init(void) |
| 104 | { |
| 105 | install_element_ve(&show_llc_cmd); |
| 106 | |
| 107 | return 0; |
| 108 | } |