Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 1 | /* OsmoBTS VTY interface */ |
| 2 | |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 3 | |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 4 | #include <stdint.h> |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 5 | #include <osmocom/vty/logging.h> |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 6 | #include <osmocom/core/linuxlist.h> |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 7 | #include "pcu_vty.h" |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 8 | #include "gprs_rlcmac.h" |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 9 | |
| 10 | enum node_type pcu_vty_go_parent(struct vty *vty) |
| 11 | { |
| 12 | switch (vty->node) { |
| 13 | #if 0 |
| 14 | case TRX_NODE: |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 15 | vty->node = PCU_NODE; |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 16 | { |
| 17 | struct gsm_bts_trx *trx = vty->index; |
| 18 | vty->index = trx->bts; |
| 19 | } |
| 20 | break; |
| 21 | #endif |
| 22 | default: |
| 23 | vty->node = CONFIG_NODE; |
| 24 | } |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 25 | return (enum node_type) vty->node; |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | int pcu_vty_is_config_node(struct vty *vty, int node) |
| 29 | { |
| 30 | switch (node) { |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 31 | case PCU_NODE: |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 32 | return 1; |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 33 | default: |
| 34 | return 0; |
| 35 | } |
| 36 | } |
| 37 | |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 38 | static struct cmd_node pcu_node = { |
| 39 | (enum node_type) PCU_NODE, |
| 40 | "%s(pcu)#", |
| 41 | 1, |
| 42 | }; |
| 43 | |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 44 | gDEFUN(ournode_exit, ournode_exit_cmd, "exit", |
| 45 | "Exit current node, go down to provious node") |
| 46 | { |
| 47 | switch (vty->node) { |
| 48 | #if 0 |
| 49 | case TRXV_NODE: |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 50 | vty->node = PCU_NODE; |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 51 | { |
| 52 | struct gsm_bts_trx *trx = vty->index; |
| 53 | vty->index = trx->bts; |
| 54 | } |
| 55 | break; |
| 56 | #endif |
| 57 | default: |
| 58 | break; |
| 59 | } |
| 60 | return CMD_SUCCESS; |
| 61 | } |
| 62 | |
| 63 | gDEFUN(ournode_end, ournode_end_cmd, "end", |
| 64 | "End current mode and change to enable mode") |
| 65 | { |
| 66 | switch (vty->node) { |
| 67 | default: |
| 68 | vty_config_unlock(vty); |
| 69 | vty->node = ENABLE_NODE; |
| 70 | vty->index = NULL; |
| 71 | vty->index_sub = NULL; |
| 72 | break; |
| 73 | } |
| 74 | return CMD_SUCCESS; |
| 75 | } |
| 76 | |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 77 | static int config_write_pcu(struct vty *vty) |
| 78 | { |
| 79 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
| 80 | |
| 81 | vty_out(vty, "pcu%s", VTY_NEWLINE); |
| 82 | if (bts->force_cs) |
| 83 | vty_out(vty, " cs %d%s", bts->initial_cs, VTY_NEWLINE); |
Andreas Eversberg | 24131bf | 2012-07-21 11:09:58 +0200 | [diff] [blame] | 84 | if (bts->force_llc_lifetime == 0xffff) |
| 85 | vty_out(vty, " queue lifetime infinite%s", VTY_NEWLINE); |
| 86 | else if (bts->force_llc_lifetime) |
| 87 | vty_out(vty, " queue lifetime %d%s", bts->force_llc_lifetime, |
| 88 | VTY_NEWLINE); |
Andreas Eversberg | a1503fa | 2012-07-22 08:58:09 +0200 | [diff] [blame] | 89 | if (bts->alloc_algorithm == alloc_algorithm_a) |
| 90 | vty_out(vty, " alloc-algorithm a%s", VTY_NEWLINE); |
| 91 | if (bts->alloc_algorithm == alloc_algorithm_b) |
| 92 | vty_out(vty, " alloc-algorithm b%s", VTY_NEWLINE); |
| 93 | |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* per-BTS configuration */ |
| 97 | DEFUN(cfg_pcu, |
| 98 | cfg_pcu_cmd, |
| 99 | "pcu", |
| 100 | "BTS specific configure") |
| 101 | { |
| 102 | vty->node = PCU_NODE; |
| 103 | |
| 104 | return CMD_SUCCESS; |
| 105 | } |
| 106 | |
| 107 | DEFUN(cfg_pcu_cs, |
| 108 | cfg_pcu_cs_cmd, |
| 109 | "cs <1-4>", |
| 110 | "Set the Coding Scheme to be used, (overrides BTS config)\n") |
| 111 | { |
| 112 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
| 113 | uint8_t cs = atoi(argv[0]); |
| 114 | |
| 115 | bts->force_cs = 1; |
| 116 | bts->initial_cs = cs; |
| 117 | |
| 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
| 121 | DEFUN(cfg_pcu_no_cs, |
| 122 | cfg_pcu_no_cs_cmd, |
| 123 | "no cs", |
| 124 | NO_STR "Don't force given Coding Scheme, (use BTS config)\n") |
| 125 | { |
| 126 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
| 127 | |
| 128 | bts->force_cs = 0; |
| 129 | |
| 130 | return CMD_SUCCESS; |
| 131 | } |
| 132 | |
Andreas Eversberg | 24131bf | 2012-07-21 11:09:58 +0200 | [diff] [blame] | 133 | #define QUEUE_STR "Packet queue options\n" |
| 134 | #define LIFETIME_STR "Set lifetime limit of LLC frame in centi-seconds " \ |
| 135 | "(overrides the value given by SGSN)\n" |
| 136 | |
| 137 | DEFUN(cfg_pcu_queue_lifetime, |
| 138 | cfg_pcu_queue_lifetime_cmd, |
| 139 | "queue lifetime <1-65534>", |
| 140 | QUEUE_STR LIFETIME_STR "Lifetime in centi-seconds") |
| 141 | { |
| 142 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
| 143 | uint8_t csec = atoi(argv[0]); |
| 144 | |
| 145 | bts->force_llc_lifetime = csec; |
| 146 | |
| 147 | return CMD_SUCCESS; |
| 148 | } |
| 149 | |
| 150 | DEFUN(cfg_pcu_queue_lifetime_inf, |
| 151 | cfg_pcu_queue_lifetime_inf_cmd, |
| 152 | "queue lifetime infinite", |
| 153 | QUEUE_STR LIFETIME_STR "Infinite lifetime") |
| 154 | { |
| 155 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
| 156 | |
| 157 | bts->force_llc_lifetime = 0xffff; |
| 158 | |
| 159 | return CMD_SUCCESS; |
| 160 | } |
| 161 | |
| 162 | DEFUN(cfg_pcu_no_queue_lifetime, |
| 163 | cfg_pcu_no_queue_lifetime_cmd, |
| 164 | "no queue lifetime", |
| 165 | NO_STR QUEUE_STR "Disable lifetime limit of LLC frame (use value given " |
| 166 | "by SGSN)\n") |
| 167 | { |
| 168 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
| 169 | |
| 170 | bts->force_llc_lifetime = 0; |
| 171 | |
| 172 | return CMD_SUCCESS; |
| 173 | } |
| 174 | |
Andreas Eversberg | a1503fa | 2012-07-22 08:58:09 +0200 | [diff] [blame] | 175 | DEFUN(cfg_pcu_alloc, |
| 176 | cfg_pcu_alloc_cmd, |
| 177 | "alloc-algorithm (a|b)", |
| 178 | "Select slot allocation algorithm to use when assigning timeslots on " |
| 179 | "PACCH\nSingle slot is assigned only\nMultiple slots are assigned for " |
| 180 | "semi-duplex operation") |
| 181 | { |
| 182 | struct gprs_rlcmac_bts *bts = gprs_rlcmac_bts; |
| 183 | |
| 184 | switch (argv[0][0]) { |
| 185 | case 'a': |
| 186 | bts->alloc_algorithm = alloc_algorithm_a; |
| 187 | break; |
| 188 | case 'b': |
| 189 | bts->alloc_algorithm = alloc_algorithm_b; |
| 190 | break; |
| 191 | } |
| 192 | |
| 193 | return CMD_SUCCESS; |
| 194 | } |
| 195 | |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 196 | static const char pcu_copyright[] = |
| 197 | "Copyright (C) 2012 by ...\r\n" |
| 198 | "License GNU GPL version 2 or later\r\n" |
| 199 | "This is free software: you are free to change and redistribute it.\r\n" |
| 200 | "There is NO WARRANTY, to the extent permitted by law.\r\n"; |
| 201 | |
| 202 | struct vty_app_info pcu_vty_info = { |
| 203 | .name = "Osmo-PCU", |
| 204 | .version = PACKAGE_VERSION, |
| 205 | .copyright = pcu_copyright, |
| 206 | .go_parent_cb = pcu_vty_go_parent, |
| 207 | .is_config_node = pcu_vty_is_config_node, |
| 208 | }; |
| 209 | |
| 210 | int pcu_vty_init(const struct log_info *cat) |
| 211 | { |
| 212 | // install_element_ve(&show_pcu_cmd); |
| 213 | |
| 214 | logging_vty_add_cmds(cat); |
| 215 | |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 216 | install_node(&pcu_node, config_write_pcu); |
| 217 | install_element(CONFIG_NODE, &cfg_pcu_cmd); |
| 218 | install_default(PCU_NODE); |
| 219 | install_element(PCU_NODE, &cfg_pcu_cs_cmd); |
| 220 | install_element(PCU_NODE, &cfg_pcu_no_cs_cmd); |
Andreas Eversberg | 24131bf | 2012-07-21 11:09:58 +0200 | [diff] [blame] | 221 | install_element(PCU_NODE, &cfg_pcu_queue_lifetime_cmd); |
| 222 | install_element(PCU_NODE, &cfg_pcu_queue_lifetime_inf_cmd); |
| 223 | install_element(PCU_NODE, &cfg_pcu_no_queue_lifetime_cmd); |
Andreas Eversberg | a1503fa | 2012-07-22 08:58:09 +0200 | [diff] [blame] | 224 | install_element(PCU_NODE, &cfg_pcu_alloc_cmd); |
Andreas Eversberg | 8b761a3 | 2012-07-20 21:50:31 +0200 | [diff] [blame] | 225 | install_element(PCU_NODE, &ournode_end_cmd); |
| 226 | |
Andreas Eversberg | 1294256 | 2012-07-12 14:31:57 +0200 | [diff] [blame] | 227 | return 0; |
| 228 | } |