Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1 | /* GSM Network Management (OML) messages on the A-bis interface |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2 | * 3GPP TS 12.21 version 8.0.0 Release 1999 / ETSI TS 100 623 V8.0.0 */ |
| 3 | |
| 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * GNU Affero General Public License for more details. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 17 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <unistd.h> |
| 26 | #include <stdio.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <libgen.h> |
| 30 | #include <time.h> |
| 31 | #include <limits.h> |
| 32 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 33 | #include <sys/stat.h> |
| 34 | #include <netinet/in.h> |
| 35 | #include <arpa/inet.h> |
| 36 | |
| 37 | #include <openbsc/gsm_data.h> |
| 38 | #include <openbsc/debug.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 39 | #include <osmocom/core/msgb.h> |
Max | 5a9d8bc | 2017-01-11 11:51:28 +0100 | [diff] [blame] | 40 | #include <osmocom/gsm/protocol/gsm_12_21.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 41 | #include <osmocom/gsm/tlv.h> |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 42 | #include <osmocom/gsm/abis_nm.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 43 | #include <osmocom/core/talloc.h> |
Neels Hofmeyr | 5644c2b | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 44 | #include <osmocom/core/utils.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 45 | #include <openbsc/abis_nm.h> |
| 46 | #include <openbsc/misdn.h> |
| 47 | #include <openbsc/signal.h> |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 48 | #include <osmocom/abis/e1_input.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 49 | |
| 50 | #define OM_ALLOC_SIZE 1024 |
| 51 | #define OM_HEADROOM_SIZE 128 |
Holger Hans Peter Freyther | b5f5448 | 2009-12-28 10:04:26 +0100 | [diff] [blame] | 52 | #define IPACC_SEGMENT_SIZE 245 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 53 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 54 | int abis_nm_tlv_parse(struct tlv_parsed *tp, struct gsm_bts *bts, const uint8_t *buf, int len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 55 | { |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 56 | if (!bts->model) |
| 57 | return -EIO; |
| 58 | return tlv_parse(tp, &bts->model->nm_att_tlvdef, buf, len, 0, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static int is_in_arr(enum abis_nm_msgtype mt, const enum abis_nm_msgtype *arr, int size) |
| 62 | { |
| 63 | int i; |
| 64 | |
| 65 | for (i = 0; i < size; i++) { |
| 66 | if (arr[i] == mt) |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | #if 0 |
| 74 | /* is this msgtype the usual ACK/NACK type ? */ |
| 75 | static int is_ack_nack(enum abis_nm_msgtype mt) |
| 76 | { |
| 77 | return !is_in_arr(mt, no_ack_nack, ARRAY_SIZE(no_ack_nack)); |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | /* is this msgtype a report ? */ |
| 82 | static int is_report(enum abis_nm_msgtype mt) |
| 83 | { |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 84 | return is_in_arr(mt, abis_nm_reports, ARRAY_SIZE(abis_nm_reports)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | #define MT_ACK(x) (x+1) |
| 88 | #define MT_NACK(x) (x+2) |
| 89 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 90 | static void fill_om_hdr(struct abis_om_hdr *oh, uint8_t len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 91 | { |
| 92 | oh->mdisc = ABIS_OM_MDISC_FOM; |
| 93 | oh->placement = ABIS_OM_PLACEMENT_ONLY; |
| 94 | oh->sequence = 0; |
| 95 | oh->length = len; |
| 96 | } |
| 97 | |
Holger Hans Peter Freyther | ffd0f22 | 2014-04-04 12:56:34 +0200 | [diff] [blame] | 98 | static struct abis_om_fom_hdr *fill_om_fom_hdr(struct abis_om_hdr *oh, uint8_t len, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 99 | uint8_t msg_type, uint8_t obj_class, |
| 100 | uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 101 | { |
| 102 | struct abis_om_fom_hdr *foh = |
| 103 | (struct abis_om_fom_hdr *) oh->data; |
| 104 | |
| 105 | fill_om_hdr(oh, len+sizeof(*foh)); |
| 106 | foh->msg_type = msg_type; |
| 107 | foh->obj_class = obj_class; |
| 108 | foh->obj_inst.bts_nr = bts_nr; |
| 109 | foh->obj_inst.trx_nr = trx_nr; |
| 110 | foh->obj_inst.ts_nr = ts_nr; |
Holger Hans Peter Freyther | ffd0f22 | 2014-04-04 12:56:34 +0200 | [diff] [blame] | 111 | return foh; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static struct msgb *nm_msgb_alloc(void) |
| 115 | { |
Harald Welte | 9cfc935 | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 116 | return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE, |
| 117 | "OML"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 118 | } |
| 119 | |
Harald Welte | 607044f | 2011-09-26 23:43:23 +0200 | [diff] [blame] | 120 | int _abis_nm_sendmsg(struct msgb *msg) |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 121 | { |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 122 | msg->l2h = msg->data; |
| 123 | |
| 124 | if (!msg->dst) { |
| 125 | LOGP(DNM, LOGL_ERROR, "%s: msg->dst == NULL\n", __func__); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 129 | return abis_sendmsg(msg); |
| 130 | } |
| 131 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 132 | /* Send a OML NM Message from BSC to BTS */ |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 133 | static int abis_nm_queue_msg(struct gsm_bts *bts, struct msgb *msg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 134 | { |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 135 | msg->dst = bts->oml_link; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 136 | |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 137 | /* queue OML messages */ |
| 138 | if (llist_empty(&bts->abis_queue) && !bts->abis_nm_pend) { |
| 139 | bts->abis_nm_pend = OBSC_NM_W_ACK_CB(msg); |
Harald Welte | 607044f | 2011-09-26 23:43:23 +0200 | [diff] [blame] | 140 | return _abis_nm_sendmsg(msg); |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 141 | } else { |
| 142 | msgb_enqueue(&bts->abis_queue, msg); |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | } |
| 147 | |
| 148 | int abis_nm_sendmsg(struct gsm_bts *bts, struct msgb *msg) |
| 149 | { |
| 150 | OBSC_NM_W_ACK_CB(msg) = 1; |
| 151 | return abis_nm_queue_msg(bts, msg); |
| 152 | } |
| 153 | |
| 154 | static int abis_nm_sendmsg_direct(struct gsm_bts *bts, struct msgb *msg) |
| 155 | { |
| 156 | OBSC_NM_W_ACK_CB(msg) = 0; |
| 157 | return abis_nm_queue_msg(bts, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static int abis_nm_rcvmsg_sw(struct msgb *mb); |
| 161 | |
Sylvain Munaut | ca3e04f | 2010-01-02 16:32:17 +0100 | [diff] [blame] | 162 | int nm_is_running(struct gsm_nm_state *s) { |
| 163 | return (s->operational == NM_OPSTATE_ENABLED) && ( |
| 164 | (s->availability == NM_AVSTATE_OK) || |
| 165 | (s->availability == 0xff) |
| 166 | ); |
| 167 | } |
| 168 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 169 | /* Update the administrative state of a given object in our in-memory data |
| 170 | * structures and send an event to the higher layer */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 171 | static int update_admstate(struct gsm_bts *bts, uint8_t obj_class, |
| 172 | struct abis_om_obj_inst *obj_inst, uint8_t adm_state) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 173 | { |
| 174 | struct gsm_nm_state *nm_state, new_state; |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 175 | struct nm_statechg_signal_data nsd; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 176 | |
Harald Welte | a348c08 | 2011-03-06 21:20:38 +0100 | [diff] [blame] | 177 | memset(&nsd, 0, sizeof(nsd)); |
| 178 | |
Harald Welte | c6ed928 | 2011-06-06 18:31:20 +0200 | [diff] [blame] | 179 | nsd.obj = gsm_objclass2obj(bts, obj_class, obj_inst); |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 180 | if (!nsd.obj) |
Harald Welte | 3d9ecf7 | 2009-11-13 12:10:18 +0100 | [diff] [blame] | 181 | return -EINVAL; |
Harald Welte | c6ed928 | 2011-06-06 18:31:20 +0200 | [diff] [blame] | 182 | nm_state = gsm_objclass2nmstate(bts, obj_class, obj_inst); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 183 | if (!nm_state) |
| 184 | return -1; |
| 185 | |
| 186 | new_state = *nm_state; |
| 187 | new_state.administrative = adm_state; |
| 188 | |
Harald Welte | b03c448 | 2011-03-06 22:11:32 +0100 | [diff] [blame] | 189 | nsd.bts = bts; |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 190 | nsd.obj_class = obj_class; |
| 191 | nsd.old_state = nm_state; |
| 192 | nsd.new_state = &new_state; |
| 193 | nsd.obj_inst = obj_inst; |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 194 | osmo_signal_dispatch(SS_NM, S_NM_STATECHG_ADM, &nsd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 195 | |
| 196 | nm_state->administrative = adm_state; |
| 197 | |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 198 | return 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static int abis_nm_rx_statechg_rep(struct msgb *mb) |
| 202 | { |
| 203 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 204 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 205 | struct e1inp_sign_link *sign_link = mb->dst; |
| 206 | struct gsm_bts *bts = sign_link->trx->bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 207 | struct tlv_parsed tp; |
| 208 | struct gsm_nm_state *nm_state, new_state; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 209 | |
| 210 | DEBUGPC(DNM, "STATE CHG: "); |
| 211 | |
| 212 | memset(&new_state, 0, sizeof(new_state)); |
| 213 | |
Harald Welte | c6ed928 | 2011-06-06 18:31:20 +0200 | [diff] [blame] | 214 | nm_state = gsm_objclass2nmstate(bts, foh->obj_class, &foh->obj_inst); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 215 | if (!nm_state) { |
Harald Welte | 3d9ecf7 | 2009-11-13 12:10:18 +0100 | [diff] [blame] | 216 | DEBUGPC(DNM, "unknown object class\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 217 | return -EINVAL; |
| 218 | } |
| 219 | |
| 220 | new_state = *nm_state; |
| 221 | |
Harald Welte | 59698fb | 2010-01-10 18:01:52 +0100 | [diff] [blame] | 222 | abis_nm_tlv_parse(&tp, bts, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 223 | if (TLVP_PRESENT(&tp, NM_ATT_OPER_STATE)) { |
| 224 | new_state.operational = *TLVP_VAL(&tp, NM_ATT_OPER_STATE); |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 225 | DEBUGPC(DNM, "OP_STATE=%s ", |
| 226 | abis_nm_opstate_name(new_state.operational)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 227 | } |
| 228 | if (TLVP_PRESENT(&tp, NM_ATT_AVAIL_STATUS)) { |
| 229 | if (TLVP_LEN(&tp, NM_ATT_AVAIL_STATUS) == 0) |
| 230 | new_state.availability = 0xff; |
| 231 | else |
| 232 | new_state.availability = *TLVP_VAL(&tp, NM_ATT_AVAIL_STATUS); |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 233 | DEBUGPC(DNM, "AVAIL=%s(%02x) ", |
| 234 | abis_nm_avail_name(new_state.availability), |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 235 | new_state.availability); |
Sylvain Munaut | 035e370 | 2010-01-02 16:35:26 +0100 | [diff] [blame] | 236 | } else |
| 237 | new_state.availability = 0xff; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 238 | if (TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) { |
| 239 | new_state.administrative = *TLVP_VAL(&tp, NM_ATT_ADM_STATE); |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 240 | DEBUGPC(DNM, "ADM=%2s ", |
Harald Welte | 73e6994 | 2011-05-23 20:42:26 +0200 | [diff] [blame] | 241 | get_value_string(abis_nm_adm_state_names, |
| 242 | new_state.administrative)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 243 | } |
| 244 | DEBUGPC(DNM, "\n"); |
| 245 | |
Holger Hans Peter Freyther | 677bb2f | 2009-12-31 03:05:52 +0100 | [diff] [blame] | 246 | if ((new_state.administrative != 0 && nm_state->administrative == 0) || |
| 247 | new_state.operational != nm_state->operational || |
| 248 | new_state.availability != nm_state->availability) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 249 | /* Update the operational state of a given object in our in-memory data |
| 250 | * structures and send an event to the higher layer */ |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 251 | struct nm_statechg_signal_data nsd; |
Harald Welte | c6ed928 | 2011-06-06 18:31:20 +0200 | [diff] [blame] | 252 | nsd.obj = gsm_objclass2obj(bts, foh->obj_class, &foh->obj_inst); |
Harald Welte | 4c826f7 | 2011-01-14 15:55:42 +0100 | [diff] [blame] | 253 | nsd.obj_class = foh->obj_class; |
| 254 | nsd.old_state = nm_state; |
| 255 | nsd.new_state = &new_state; |
| 256 | nsd.obj_inst = &foh->obj_inst; |
Harald Welte | b03c448 | 2011-03-06 22:11:32 +0100 | [diff] [blame] | 257 | nsd.bts = bts; |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 258 | osmo_signal_dispatch(SS_NM, S_NM_STATECHG_OPER, &nsd); |
Holger Hans Peter Freyther | 677bb2f | 2009-12-31 03:05:52 +0100 | [diff] [blame] | 259 | nm_state->operational = new_state.operational; |
| 260 | nm_state->availability = new_state.availability; |
| 261 | if (nm_state->administrative == 0) |
| 262 | nm_state->administrative = new_state.administrative; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 263 | } |
| 264 | #if 0 |
| 265 | if (op_state == 1) { |
| 266 | /* try to enable objects that are disabled */ |
| 267 | abis_nm_opstart(bts, foh->obj_class, |
| 268 | foh->obj_inst.bts_nr, |
| 269 | foh->obj_inst.trx_nr, |
| 270 | foh->obj_inst.ts_nr); |
| 271 | } |
| 272 | #endif |
| 273 | return 0; |
| 274 | } |
| 275 | |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 276 | static inline void log_oml_fail_rep(const struct gsm_bts *bts, const char *type, |
| 277 | const char *severity, const uint8_t *p_val, |
| 278 | const char *text) |
| 279 | { |
| 280 | enum abis_nm_pcause_type pcause = p_val[0]; |
| 281 | enum abis_mm_event_causes cause = osmo_load16be(p_val + 1); |
| 282 | |
| 283 | LOGPC(DNM, LOGL_ERROR, "BTS %u: Failure Event Report: ", bts->nr); |
| 284 | if (type) |
| 285 | LOGPC(DNM, LOGL_ERROR, "Type=%s, ", type); |
| 286 | if (severity) |
| 287 | LOGPC(DNM, LOGL_ERROR, "Severity=%s, ", severity); |
| 288 | |
| 289 | LOGPC(DNM, LOGL_ERROR, "Probable cause=%s: ", |
| 290 | get_value_string(abis_nm_pcause_type_names, pcause)); |
| 291 | |
| 292 | if (pcause == NM_PCAUSE_T_MANUF) |
| 293 | LOGPC(DNM, LOGL_ERROR, "%s, ", |
| 294 | get_value_string(abis_mm_event_cause_names, cause)); |
| 295 | else |
| 296 | LOGPC(DNM, LOGL_ERROR, "%02X %02X ", p_val[1], p_val[2]); |
| 297 | |
| 298 | if (text) { |
| 299 | LOGPC(DNM, LOGL_ERROR, "Additional Text=%s. ", text); |
| 300 | } |
| 301 | |
| 302 | LOGPC(DNM, LOGL_ERROR, "\n"); |
| 303 | } |
| 304 | |
| 305 | static inline void handle_manufact_report(const struct gsm_bts *bts, |
| 306 | const uint8_t *p_val, const char *type, |
| 307 | const char *severity, const char *text) |
| 308 | { |
| 309 | enum abis_mm_event_causes cause = osmo_load16be(p_val + 1); |
| 310 | |
| 311 | switch (cause) { |
| 312 | case OSMO_EVT_PCU_VERS: |
| 313 | if (text) |
| 314 | LOGPC(DNM, LOGL_NOTICE, |
| 315 | "BTS %u reported connected PCU version %s\n", |
| 316 | bts->nr, text); |
| 317 | else |
| 318 | LOGPC(DNM, LOGL_ERROR, |
| 319 | "BTS %u sent %s without actual version string.\n", |
| 320 | bts->nr, |
| 321 | get_value_string(abis_mm_event_cause_names, |
| 322 | cause)); |
| 323 | break; |
| 324 | default: |
| 325 | log_oml_fail_rep(bts, type, severity, p_val, text); |
| 326 | }; |
| 327 | } |
| 328 | |
| 329 | static int rx_fail_evt_rep(struct msgb *mb, const struct gsm_bts *bts) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 330 | { |
| 331 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 332 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 333 | struct e1inp_sign_link *sign_link = mb->dst; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 334 | struct tlv_parsed tp; |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 335 | int rc = 0; |
| 336 | const uint8_t *p_val = NULL; |
| 337 | char *p_text = NULL; |
| 338 | const char *e_type = NULL, *severity = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 339 | |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 340 | abis_nm_tlv_parse(&tp, sign_link->trx->bts, foh->data, |
| 341 | oh->length-sizeof(*foh)); |
Max | 5a9d8bc | 2017-01-11 11:51:28 +0100 | [diff] [blame] | 342 | |
Dieter Spaar | f5888a7 | 2011-02-18 11:06:51 +0100 | [diff] [blame] | 343 | if (TLVP_PRESENT(&tp, NM_ATT_ADD_TEXT)) { |
| 344 | p_val = TLVP_VAL(&tp, NM_ATT_ADD_TEXT); |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 345 | p_text = talloc_strndup(tall_bsc_ctx, (const char *) p_val, |
| 346 | TLVP_LEN(&tp, NM_ATT_ADD_TEXT)); |
Dieter Spaar | f5888a7 | 2011-02-18 11:06:51 +0100 | [diff] [blame] | 347 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 348 | |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 349 | if (TLVP_PRESENT(&tp, NM_ATT_EVENT_TYPE)) |
| 350 | e_type = abis_nm_event_type_name(*TLVP_VAL(&tp, |
| 351 | NM_ATT_EVENT_TYPE)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 352 | |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 353 | if (TLVP_PRESENT(&tp, NM_ATT_SEVERITY)) |
| 354 | severity = abis_nm_severity_name(*TLVP_VAL(&tp, |
| 355 | NM_ATT_SEVERITY)); |
| 356 | |
| 357 | if (TLVP_PRESENT(&tp, NM_ATT_PROB_CAUSE)) { |
| 358 | p_val = TLVP_VAL(&tp, NM_ATT_PROB_CAUSE); |
| 359 | |
| 360 | switch (p_val[0]) { |
| 361 | case NM_PCAUSE_T_MANUF: |
| 362 | handle_manufact_report(bts, p_val, e_type, severity, |
| 363 | p_text); |
| 364 | break; |
| 365 | default: |
| 366 | log_oml_fail_rep(bts, e_type, severity, p_val, p_text); |
| 367 | }; |
| 368 | } else { |
| 369 | LOGPC(DNM, LOGL_ERROR, "BTS%u: Failure Event Report without " |
| 370 | "Probable Cause?!\n", bts->nr); |
| 371 | rc = -EINVAL; |
| 372 | } |
| 373 | |
| 374 | if (p_text) |
| 375 | talloc_free(p_text); |
| 376 | |
| 377 | return rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 378 | } |
| 379 | |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 380 | static int abis_nm_rcvmsg_report(struct msgb *mb, struct gsm_bts *bts) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 381 | { |
| 382 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 383 | uint8_t mt = foh->msg_type; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 384 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 385 | abis_nm_debugp_foh(DNM, foh); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 386 | |
| 387 | //nmh->cfg->report_cb(mb, foh); |
| 388 | |
| 389 | switch (mt) { |
| 390 | case NM_MT_STATECHG_EVENT_REP: |
| 391 | return abis_nm_rx_statechg_rep(mb); |
| 392 | break; |
| 393 | case NM_MT_SW_ACTIVATED_REP: |
| 394 | DEBUGPC(DNM, "Software Activated Report\n"); |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 395 | osmo_signal_dispatch(SS_NM, S_NM_SW_ACTIV_REP, mb); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 396 | break; |
| 397 | case NM_MT_FAILURE_EVENT_REP: |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 398 | rx_fail_evt_rep(mb, bts); |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 399 | osmo_signal_dispatch(SS_NM, S_NM_FAIL_REP, mb); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 400 | break; |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 401 | case NM_MT_TEST_REP: |
| 402 | DEBUGPC(DNM, "Test Report\n"); |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 403 | osmo_signal_dispatch(SS_NM, S_NM_TEST_REP, mb); |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 404 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 405 | default: |
| 406 | DEBUGPC(DNM, "reporting NM MT 0x%02x\n", mt); |
| 407 | break; |
| 408 | |
| 409 | }; |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | /* Activate the specified software into the BTS */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 415 | static int ipacc_sw_activate(struct gsm_bts *bts, uint8_t obj_class, uint8_t i0, uint8_t i1, |
| 416 | uint8_t i2, const uint8_t *sw_desc, uint8_t swdesc_len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 417 | { |
| 418 | struct abis_om_hdr *oh; |
| 419 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 420 | uint8_t len = swdesc_len; |
| 421 | uint8_t *trailer; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 422 | |
| 423 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 424 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, obj_class, i0, i1, i2); |
| 425 | |
| 426 | trailer = msgb_put(msg, swdesc_len); |
| 427 | memcpy(trailer, sw_desc, swdesc_len); |
| 428 | |
| 429 | return abis_nm_sendmsg(bts, msg); |
| 430 | } |
| 431 | |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 432 | int abis_nm_parse_sw_config(const uint8_t *sw_descr, const size_t sw_descr_len, |
| 433 | struct abis_nm_sw_descr *desc, const int res_len) |
Sylvain Munaut | 7e3edbf | 2009-10-25 17:48:42 +0100 | [diff] [blame] | 434 | { |
| 435 | static const struct tlv_definition sw_descr_def = { |
| 436 | .def = { |
| 437 | [NM_ATT_FILE_ID] = { TLV_TYPE_TL16V, }, |
| 438 | [NM_ATT_FILE_VERSION] = { TLV_TYPE_TL16V, }, |
| 439 | }, |
| 440 | }; |
| 441 | |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 442 | size_t pos = 0; |
| 443 | int desc_pos = 0; |
Sylvain Munaut | 7e3edbf | 2009-10-25 17:48:42 +0100 | [diff] [blame] | 444 | |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 445 | for (pos = 0; pos < sw_descr_len && desc_pos < res_len; ++desc_pos) { |
| 446 | uint8_t tag; |
| 447 | uint16_t tag_len; |
| 448 | const uint8_t *val; |
| 449 | int len; |
Sylvain Munaut | 7e3edbf | 2009-10-25 17:48:42 +0100 | [diff] [blame] | 450 | |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 451 | memset(&desc[desc_pos], 0, sizeof(desc[desc_pos])); |
| 452 | desc[desc_pos].start = &sw_descr[pos]; |
| 453 | |
| 454 | /* Classic TLV parsing doesn't work well with SW_DESCR because of it's |
| 455 | * nested nature and the fact you have to assume it contains only two sub |
| 456 | * tags NM_ATT_FILE_VERSION & NM_ATT_FILE_ID to parse it */ |
| 457 | if (sw_descr[pos] != NM_ATT_SW_DESCR) { |
| 458 | LOGP(DNM, LOGL_ERROR, |
| 459 | "SW_DESCR attribute identifier not found!\n"); |
| 460 | return -1; |
| 461 | } |
| 462 | |
| 463 | pos += 1; |
| 464 | len = tlv_parse_one(&tag, &tag_len, &val, |
| 465 | &sw_descr_def, &sw_descr[pos], sw_descr_len - pos); |
| 466 | if (len < 0 || (tag != NM_ATT_FILE_ID)) { |
| 467 | LOGP(DNM, LOGL_ERROR, |
| 468 | "FILE_ID attribute identifier not found!\n"); |
| 469 | return -2; |
| 470 | } |
| 471 | desc[desc_pos].file_id = val; |
| 472 | desc[desc_pos].file_id_len = tag_len; |
| 473 | pos += len; |
| 474 | |
| 475 | |
| 476 | len = tlv_parse_one(&tag, &tag_len, &val, |
| 477 | &sw_descr_def, &sw_descr[pos], sw_descr_len - pos); |
| 478 | if (len < 0 || (tag != NM_ATT_FILE_VERSION)) { |
| 479 | LOGP(DNM, LOGL_ERROR, |
| 480 | "FILE_VERSION attribute identifier not found!\n"); |
| 481 | return -3; |
| 482 | } |
| 483 | desc[desc_pos].file_ver = val; |
| 484 | desc[desc_pos].file_ver_len = tag_len; |
| 485 | pos += len; |
| 486 | |
| 487 | /* final size */ |
| 488 | desc[desc_pos].len = &sw_descr[pos] - desc[desc_pos].start; |
Sylvain Munaut | 7e3edbf | 2009-10-25 17:48:42 +0100 | [diff] [blame] | 489 | } |
Sylvain Munaut | 7e3edbf | 2009-10-25 17:48:42 +0100 | [diff] [blame] | 490 | |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 491 | return desc_pos; |
Sylvain Munaut | 7e3edbf | 2009-10-25 17:48:42 +0100 | [diff] [blame] | 492 | } |
| 493 | |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 494 | int abis_nm_select_newest_sw(const struct abis_nm_sw_descr *sw_descr, |
| 495 | const size_t size) |
| 496 | { |
| 497 | int res = 0; |
| 498 | int i; |
| 499 | |
| 500 | for (i = 1; i < size; ++i) { |
| 501 | if (memcmp(sw_descr[res].file_ver, sw_descr[i].file_ver, |
| 502 | OSMO_MIN(sw_descr[i].file_ver_len, sw_descr[res].file_ver_len)) < 0) { |
| 503 | res = i; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | return res; |
| 508 | } |
| 509 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 510 | static int abis_nm_rx_sw_act_req(struct msgb *mb) |
| 511 | { |
| 512 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 513 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 514 | struct e1inp_sign_link *sign_link = mb->dst; |
Mike Haben | 322fc58 | 2009-10-01 14:56:13 +0200 | [diff] [blame] | 515 | struct tlv_parsed tp; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 516 | const uint8_t *sw_config; |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 517 | int ret, sw_config_len, len; |
| 518 | struct abis_nm_sw_descr sw_descr[5]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 519 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 520 | abis_nm_debugp_foh(DNM, foh); |
Harald Welte | b7284a9 | 2009-10-20 09:56:18 +0200 | [diff] [blame] | 521 | |
| 522 | DEBUGPC(DNM, "SW Activate Request: "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 523 | |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 524 | DEBUGP(DNM, "Software Activate Request, ACKing and Activating\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 525 | |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 526 | ret = abis_nm_sw_act_req_ack(sign_link->trx->bts, foh->obj_class, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 527 | foh->obj_inst.bts_nr, |
| 528 | foh->obj_inst.trx_nr, |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 529 | foh->obj_inst.ts_nr, 0, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 530 | foh->data, oh->length-sizeof(*foh)); |
Holger Hans Peter Freyther | 22ef555 | 2012-02-03 19:48:30 +0100 | [diff] [blame] | 531 | if (ret != 0) { |
| 532 | LOGP(DNM, LOGL_ERROR, |
| 533 | "Sending SW ActReq ACK failed: %d\n", ret); |
| 534 | return ret; |
| 535 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 536 | |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 537 | abis_nm_tlv_parse(&tp, sign_link->trx->bts, foh->data, oh->length-sizeof(*foh)); |
Mike Haben | 322fc58 | 2009-10-01 14:56:13 +0200 | [diff] [blame] | 538 | sw_config = TLVP_VAL(&tp, NM_ATT_SW_CONFIG); |
| 539 | sw_config_len = TLVP_LEN(&tp, NM_ATT_SW_CONFIG); |
| 540 | if (!TLVP_PRESENT(&tp, NM_ATT_SW_CONFIG)) { |
Holger Hans Peter Freyther | 22ef555 | 2012-02-03 19:48:30 +0100 | [diff] [blame] | 541 | LOGP(DNM, LOGL_ERROR, |
| 542 | "SW config not found! Can't continue.\n"); |
Mike Haben | 322fc58 | 2009-10-01 14:56:13 +0200 | [diff] [blame] | 543 | return -EINVAL; |
| 544 | } else { |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 545 | DEBUGP(DNM, "Found SW config: %s\n", osmo_hexdump(sw_config, sw_config_len)); |
Mike Haben | 322fc58 | 2009-10-01 14:56:13 +0200 | [diff] [blame] | 546 | } |
| 547 | |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 548 | /* Parse up to two sw descriptions from the data */ |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 549 | len = abis_nm_parse_sw_config(sw_config, sw_config_len, |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 550 | &sw_descr[0], ARRAY_SIZE(sw_descr)); |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 551 | if (len <= 0) { |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 552 | LOGP(DNM, LOGL_ERROR, "Failed to parse SW Config.\n"); |
Sylvain Munaut | 7e3edbf | 2009-10-25 17:48:42 +0100 | [diff] [blame] | 553 | return -EINVAL; |
Holger Hans Peter Freyther | 23e8000 | 2012-11-22 14:59:46 +0100 | [diff] [blame] | 554 | } |
Mike Haben | 322fc58 | 2009-10-01 14:56:13 +0200 | [diff] [blame] | 555 | |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 556 | ret = abis_nm_select_newest_sw(&sw_descr[0], len); |
| 557 | DEBUGP(DNM, "Selected sw description %d of %d\n", ret, len); |
| 558 | |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 559 | return ipacc_sw_activate(sign_link->trx->bts, foh->obj_class, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 560 | foh->obj_inst.bts_nr, |
| 561 | foh->obj_inst.trx_nr, |
| 562 | foh->obj_inst.ts_nr, |
Holger Hans Peter Freyther | 3cb4409 | 2012-11-22 19:04:10 +0100 | [diff] [blame] | 563 | sw_descr[ret].start, sw_descr[ret].len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* Receive a CHANGE_ADM_STATE_ACK, parse the TLV and update local state */ |
| 567 | static int abis_nm_rx_chg_adm_state_ack(struct msgb *mb) |
| 568 | { |
| 569 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 570 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 571 | struct e1inp_sign_link *sign_link = mb->dst; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 572 | struct tlv_parsed tp; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 573 | uint8_t adm_state; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 574 | |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 575 | abis_nm_tlv_parse(&tp, sign_link->trx->bts, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 576 | if (!TLVP_PRESENT(&tp, NM_ATT_ADM_STATE)) |
| 577 | return -EINVAL; |
| 578 | |
| 579 | adm_state = *TLVP_VAL(&tp, NM_ATT_ADM_STATE); |
| 580 | |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 581 | return update_admstate(sign_link->trx->bts, foh->obj_class, &foh->obj_inst, adm_state); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | static int abis_nm_rx_lmt_event(struct msgb *mb) |
| 585 | { |
| 586 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 587 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 588 | struct e1inp_sign_link *sign_link = mb->dst; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 589 | struct tlv_parsed tp; |
| 590 | |
| 591 | DEBUGP(DNM, "LMT Event "); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 592 | abis_nm_tlv_parse(&tp, sign_link->trx->bts, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 593 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) && |
| 594 | TLVP_LEN(&tp, NM_ATT_BS11_LMT_LOGON_SESSION) >= 1) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 595 | uint8_t onoff = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_LOGON_SESSION); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 596 | DEBUGPC(DNM, "LOG%s ", onoff ? "ON" : "OFF"); |
| 597 | } |
| 598 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) && |
| 599 | TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV) >= 1) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 600 | uint8_t level = *TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_ACC_LEV); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 601 | DEBUGPC(DNM, "Level=%u ", level); |
| 602 | } |
| 603 | if (TLVP_PRESENT(&tp, NM_ATT_BS11_LMT_USER_NAME) && |
| 604 | TLVP_LEN(&tp, NM_ATT_BS11_LMT_USER_NAME) >= 1) { |
| 605 | char *name = (char *) TLVP_VAL(&tp, NM_ATT_BS11_LMT_USER_NAME); |
| 606 | DEBUGPC(DNM, "Username=%s ", name); |
| 607 | } |
| 608 | DEBUGPC(DNM, "\n"); |
| 609 | /* FIXME: parse LMT LOGON TIME */ |
| 610 | return 0; |
| 611 | } |
| 612 | |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 613 | void abis_nm_queue_send_next(struct gsm_bts *bts) |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 614 | { |
| 615 | int wait = 0; |
| 616 | struct msgb *msg; |
| 617 | /* the queue is empty */ |
| 618 | while (!llist_empty(&bts->abis_queue)) { |
| 619 | msg = msgb_dequeue(&bts->abis_queue); |
| 620 | wait = OBSC_NM_W_ACK_CB(msg); |
Harald Welte | 607044f | 2011-09-26 23:43:23 +0200 | [diff] [blame] | 621 | _abis_nm_sendmsg(msg); |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 622 | |
| 623 | if (wait) |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | bts->abis_nm_pend = wait; |
| 628 | } |
| 629 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 630 | /* Receive a OML NM Message from BTS */ |
| 631 | static int abis_nm_rcvmsg_fom(struct msgb *mb) |
| 632 | { |
| 633 | struct abis_om_hdr *oh = msgb_l2(mb); |
| 634 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 635 | struct e1inp_sign_link *sign_link = mb->dst; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 636 | uint8_t mt = foh->msg_type; |
Jacob Erlbeck | 38c33fc | 2014-11-10 08:30:31 +0100 | [diff] [blame] | 637 | /* sign_link might get deleted via osmo_signal_dispatch -> save bts */ |
| 638 | struct gsm_bts *bts = sign_link->trx->bts; |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 639 | int ret = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 640 | |
| 641 | /* check for unsolicited message */ |
| 642 | if (is_report(mt)) |
Max | ab4b150 | 2017-03-15 14:30:21 +0100 | [diff] [blame] | 643 | return abis_nm_rcvmsg_report(mb, bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 644 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 645 | if (is_in_arr(mt, abis_nm_sw_load_msgs, ARRAY_SIZE(abis_nm_sw_load_msgs))) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 646 | return abis_nm_rcvmsg_sw(mb); |
| 647 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 648 | if (is_in_arr(mt, abis_nm_nacks, ARRAY_SIZE(abis_nm_nacks))) { |
Holger Hans Peter Freyther | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 649 | struct nm_nack_signal_data nack_data; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 650 | struct tlv_parsed tp; |
Harald Welte | 935d10b | 2009-10-08 20:18:59 +0200 | [diff] [blame] | 651 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 652 | abis_nm_debugp_foh(DNM, foh); |
Harald Welte | 935d10b | 2009-10-08 20:18:59 +0200 | [diff] [blame] | 653 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 654 | DEBUGPC(DNM, "%s NACK ", abis_nm_nack_name(mt)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 655 | |
Jacob Erlbeck | 38c33fc | 2014-11-10 08:30:31 +0100 | [diff] [blame] | 656 | abis_nm_tlv_parse(&tp, bts, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 657 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 658 | DEBUGPC(DNM, "CAUSE=%s\n", |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 659 | abis_nm_nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 660 | else |
| 661 | DEBUGPC(DNM, "\n"); |
Holger Hans Peter Freyther | efedf94 | 2009-06-10 10:48:14 +0200 | [diff] [blame] | 662 | |
Holger Hans Peter Freyther | dfea6c8 | 2010-07-14 02:08:35 +0800 | [diff] [blame] | 663 | nack_data.msg = mb; |
| 664 | nack_data.mt = mt; |
Jacob Erlbeck | 38c33fc | 2014-11-10 08:30:31 +0100 | [diff] [blame] | 665 | nack_data.bts = bts; |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 666 | osmo_signal_dispatch(SS_NM, S_NM_NACK, &nack_data); |
Jacob Erlbeck | 38c33fc | 2014-11-10 08:30:31 +0100 | [diff] [blame] | 667 | abis_nm_queue_send_next(bts); |
Holger Hans Peter Freyther | efedf94 | 2009-06-10 10:48:14 +0200 | [diff] [blame] | 668 | return 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 669 | } |
| 670 | #if 0 |
| 671 | /* check if last message is to be acked */ |
| 672 | if (is_ack_nack(nmh->last_msgtype)) { |
| 673 | if (mt == MT_ACK(nmh->last_msgtype)) { |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 674 | DEBUGP(DNM, "received ACK (0x%x)\n", foh->msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 675 | /* we got our ACK, continue sending the next msg */ |
| 676 | } else if (mt == MT_NACK(nmh->last_msgtype)) { |
| 677 | /* we got a NACK, signal this to the caller */ |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 678 | DEBUGP(DNM, "received NACK (0x%x)\n", foh->msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 679 | /* FIXME: somehow signal this to the caller */ |
| 680 | } else { |
| 681 | /* really strange things happen */ |
| 682 | return -EINVAL; |
| 683 | } |
| 684 | } |
| 685 | #endif |
| 686 | |
| 687 | switch (mt) { |
| 688 | case NM_MT_CHG_ADM_STATE_ACK: |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 689 | ret = abis_nm_rx_chg_adm_state_ack(mb); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 690 | break; |
| 691 | case NM_MT_SW_ACT_REQ: |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 692 | ret = abis_nm_rx_sw_act_req(mb); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 693 | break; |
| 694 | case NM_MT_BS11_LMT_SESSION: |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 695 | ret = abis_nm_rx_lmt_event(mb); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 696 | break; |
Max | 7efc263 | 2017-04-04 19:21:24 +0200 | [diff] [blame] | 697 | case NM_MT_OPSTART_ACK: |
| 698 | abis_nm_debugp_foh(DNM, foh); |
| 699 | DEBUGPC(DNM, "Opstart ACK\n"); |
| 700 | break; |
| 701 | case NM_MT_SET_CHAN_ATTR_ACK: |
| 702 | abis_nm_debugp_foh(DNM, foh); |
| 703 | DEBUGPC(DNM, "Set Channel Attributes ACK\n"); |
| 704 | break; |
| 705 | case NM_MT_SET_RADIO_ATTR_ACK: |
| 706 | abis_nm_debugp_foh(DNM, foh); |
| 707 | DEBUGPC(DNM, "Set Radio Carrier Attributes ACK\n"); |
| 708 | break; |
Harald Welte | 204317e | 2009-08-06 17:58:31 +0200 | [diff] [blame] | 709 | case NM_MT_CONN_MDROP_LINK_ACK: |
Max | 7efc263 | 2017-04-04 19:21:24 +0200 | [diff] [blame] | 710 | abis_nm_debugp_foh(DNM, foh); |
| 711 | DEBUGPC(DNM, "CONN MDROP LINK ACK\n"); |
Harald Welte | 204317e | 2009-08-06 17:58:31 +0200 | [diff] [blame] | 712 | break; |
Holger Hans Peter Freyther | 9ef8e5a | 2009-12-30 09:00:01 +0100 | [diff] [blame] | 713 | case NM_MT_IPACC_RESTART_ACK: |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 714 | osmo_signal_dispatch(SS_NM, S_NM_IPACC_RESTART_ACK, NULL); |
Holger Hans Peter Freyther | 9ef8e5a | 2009-12-30 09:00:01 +0100 | [diff] [blame] | 715 | break; |
| 716 | case NM_MT_IPACC_RESTART_NACK: |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 717 | osmo_signal_dispatch(SS_NM, S_NM_IPACC_RESTART_NACK, NULL); |
Holger Hans Peter Freyther | 9ef8e5a | 2009-12-30 09:00:01 +0100 | [diff] [blame] | 718 | break; |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 719 | case NM_MT_SET_BTS_ATTR_ACK: |
Harald Welte | 08011e2 | 2011-03-04 13:41:31 +0100 | [diff] [blame] | 720 | break; |
Max | 7efc263 | 2017-04-04 19:21:24 +0200 | [diff] [blame] | 721 | default: |
| 722 | abis_nm_debugp_foh(DNM, foh); |
| 723 | LOGPC(DNM, LOGL_ERROR, "Unhandled message %s\n", |
| 724 | get_value_string(abis_nm_msgtype_names, mt)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 725 | } |
| 726 | |
Jacob Erlbeck | 38c33fc | 2014-11-10 08:30:31 +0100 | [diff] [blame] | 727 | abis_nm_queue_send_next(bts); |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 728 | return ret; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | static int abis_nm_rx_ipacc(struct msgb *mb); |
| 732 | |
| 733 | static int abis_nm_rcvmsg_manuf(struct msgb *mb) |
| 734 | { |
| 735 | int rc; |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 736 | struct e1inp_sign_link *sign_link = mb->dst; |
| 737 | int bts_type = sign_link->trx->bts->type; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 738 | |
| 739 | switch (bts_type) { |
Mike Haben | 66e0ba0 | 2009-10-02 12:19:34 +0100 | [diff] [blame] | 740 | case GSM_BTS_TYPE_NANOBTS: |
Max | abf3eb1 | 2017-03-23 12:01:07 +0100 | [diff] [blame] | 741 | case GSM_BTS_TYPE_OSMOBTS: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 742 | rc = abis_nm_rx_ipacc(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 743 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 744 | break; |
| 745 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 746 | LOGP(DNM, LOGL_ERROR, "don't know how to parse OML for this " |
| 747 | "BTS type (%u)\n", bts_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 748 | rc = 0; |
| 749 | break; |
| 750 | } |
| 751 | |
| 752 | return rc; |
| 753 | } |
| 754 | |
| 755 | /* High-Level API */ |
| 756 | /* Entry-point where L2 OML from BTS enters the NM code */ |
| 757 | int abis_nm_rcvmsg(struct msgb *msg) |
| 758 | { |
| 759 | struct abis_om_hdr *oh = msgb_l2(msg); |
| 760 | int rc = 0; |
| 761 | |
| 762 | /* Various consistency checks */ |
| 763 | if (oh->placement != ABIS_OM_PLACEMENT_ONLY) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 764 | LOGP(DNM, LOGL_ERROR, "ABIS OML placement 0x%x not supported\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 765 | oh->placement); |
Pablo Neira Ayuso | d96c8c0 | 2012-10-18 19:03:52 +0200 | [diff] [blame] | 766 | if (oh->placement != ABIS_OM_PLACEMENT_FIRST) { |
| 767 | rc = -EINVAL; |
| 768 | goto err; |
| 769 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 770 | } |
| 771 | if (oh->sequence != 0) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 772 | LOGP(DNM, LOGL_ERROR, "ABIS OML sequence 0x%x != 0x00\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 773 | oh->sequence); |
Pablo Neira Ayuso | d96c8c0 | 2012-10-18 19:03:52 +0200 | [diff] [blame] | 774 | rc = -EINVAL; |
| 775 | goto err; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 776 | } |
| 777 | #if 0 |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 778 | unsigned int l2_len = msg->tail - (uint8_t *)msgb_l2(msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 779 | unsigned int hlen = sizeof(*oh) + sizeof(struct abis_om_fom_hdr); |
| 780 | if (oh->length + hlen > l2_len) { |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 781 | LOGP(DNM, LOGL_ERROR, "ABIS OML truncated message (%u > %u)\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 782 | oh->length + sizeof(*oh), l2_len); |
| 783 | return -EINVAL; |
| 784 | } |
| 785 | if (oh->length + hlen < l2_len) |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 786 | LOGP(DNM, LOGL_ERROR, "ABIS OML message with extra trailer?!? (oh->len=%d, sizeof_oh=%d l2_len=%d\n", oh->length, sizeof(*oh), l2_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 787 | #endif |
| 788 | msg->l3h = (unsigned char *)oh + sizeof(*oh); |
| 789 | |
| 790 | switch (oh->mdisc) { |
| 791 | case ABIS_OM_MDISC_FOM: |
| 792 | rc = abis_nm_rcvmsg_fom(msg); |
| 793 | break; |
| 794 | case ABIS_OM_MDISC_MANUF: |
| 795 | rc = abis_nm_rcvmsg_manuf(msg); |
| 796 | break; |
| 797 | case ABIS_OM_MDISC_MMI: |
| 798 | case ABIS_OM_MDISC_TRAU: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 799 | LOGP(DNM, LOGL_ERROR, "unimplemented ABIS OML message discriminator 0x%x\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 800 | oh->mdisc); |
| 801 | break; |
| 802 | default: |
Harald Welte | cf2ec4a | 2009-12-17 23:10:46 +0100 | [diff] [blame] | 803 | LOGP(DNM, LOGL_ERROR, "unknown ABIS OML message discriminator 0x%x\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 804 | oh->mdisc); |
Pablo Neira Ayuso | d96c8c0 | 2012-10-18 19:03:52 +0200 | [diff] [blame] | 805 | rc = -EINVAL; |
| 806 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 807 | } |
Pablo Neira Ayuso | d96c8c0 | 2012-10-18 19:03:52 +0200 | [diff] [blame] | 808 | err: |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 809 | msgb_free(msg); |
| 810 | return rc; |
| 811 | } |
| 812 | |
| 813 | #if 0 |
| 814 | /* initialized all resources */ |
| 815 | struct abis_nm_h *abis_nm_init(struct abis_nm_cfg *cfg) |
| 816 | { |
| 817 | struct abis_nm_h *nmh; |
| 818 | |
| 819 | nmh = malloc(sizeof(*nmh)); |
| 820 | if (!nmh) |
| 821 | return NULL; |
| 822 | |
| 823 | nmh->cfg = cfg; |
| 824 | |
| 825 | return nmh; |
| 826 | } |
| 827 | |
| 828 | /* free all resources */ |
| 829 | void abis_nm_fini(struct abis_nm_h *nmh) |
| 830 | { |
| 831 | free(nmh); |
| 832 | } |
| 833 | #endif |
| 834 | |
| 835 | /* Here we are trying to define a high-level API that can be used by |
| 836 | * the actual BSC implementation. However, the architecture is currently |
| 837 | * still under design. Ideally the calls to this API would be synchronous, |
| 838 | * while the underlying stack behind the APi runs in a traditional select |
| 839 | * based state machine. |
| 840 | */ |
| 841 | |
| 842 | /* 6.2 Software Load: */ |
| 843 | enum sw_state { |
| 844 | SW_STATE_NONE, |
| 845 | SW_STATE_WAIT_INITACK, |
| 846 | SW_STATE_WAIT_SEGACK, |
| 847 | SW_STATE_WAIT_ENDACK, |
| 848 | SW_STATE_WAIT_ACTACK, |
| 849 | SW_STATE_ERROR, |
| 850 | }; |
| 851 | |
| 852 | struct abis_nm_sw { |
| 853 | struct gsm_bts *bts; |
Holger Hans Peter Freyther | 2b4083a | 2010-05-12 23:51:46 +0800 | [diff] [blame] | 854 | int trx_nr; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 855 | gsm_cbfn *cbfn; |
| 856 | void *cb_data; |
| 857 | int forced; |
| 858 | |
| 859 | /* this will become part of the SW LOAD INITIATE */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 860 | uint8_t obj_class; |
| 861 | uint8_t obj_instance[3]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 862 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 863 | uint8_t file_id[255]; |
| 864 | uint8_t file_id_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 865 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 866 | uint8_t file_version[255]; |
| 867 | uint8_t file_version_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 868 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 869 | uint8_t window_size; |
| 870 | uint8_t seg_in_window; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 871 | |
| 872 | int fd; |
| 873 | FILE *stream; |
| 874 | enum sw_state state; |
| 875 | int last_seg; |
| 876 | }; |
| 877 | |
| 878 | static struct abis_nm_sw g_sw; |
| 879 | |
Holger Hans Peter Freyther | d617f56 | 2009-12-30 09:23:48 +0100 | [diff] [blame] | 880 | static void sw_add_file_id_and_ver(struct abis_nm_sw *sw, struct msgb *msg) |
| 881 | { |
| 882 | if (sw->bts->type == GSM_BTS_TYPE_NANOBTS) { |
| 883 | msgb_v_put(msg, NM_ATT_SW_DESCR); |
| 884 | msgb_tl16v_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 885 | msgb_tl16v_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 886 | sw->file_version); |
| 887 | } else if (sw->bts->type == GSM_BTS_TYPE_BS11) { |
| 888 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 889 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 890 | sw->file_version); |
| 891 | } else { |
| 892 | LOGP(DNM, LOGL_ERROR, "Please implement this for the BTS.\n"); |
| 893 | } |
| 894 | } |
| 895 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 896 | /* 6.2.1 / 8.3.1: Load Data Initiate */ |
| 897 | static int sw_load_init(struct abis_nm_sw *sw) |
| 898 | { |
| 899 | struct abis_om_hdr *oh; |
| 900 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 901 | uint8_t len = 3*2 + sw->file_id_len + sw->file_version_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 902 | |
| 903 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 904 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_INIT, sw->obj_class, |
| 905 | sw->obj_instance[0], sw->obj_instance[1], |
| 906 | sw->obj_instance[2]); |
Holger Hans Peter Freyther | 3890700 | 2009-12-28 09:02:41 +0100 | [diff] [blame] | 907 | |
Holger Hans Peter Freyther | d617f56 | 2009-12-30 09:23:48 +0100 | [diff] [blame] | 908 | sw_add_file_id_and_ver(sw, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 909 | msgb_tv_put(msg, NM_ATT_WINDOW_SIZE, sw->window_size); |
| 910 | |
| 911 | return abis_nm_sendmsg(sw->bts, msg); |
| 912 | } |
| 913 | |
| 914 | static int is_last_line(FILE *stream) |
| 915 | { |
| 916 | char next_seg_buf[256]; |
| 917 | long pos; |
| 918 | |
| 919 | /* check if we're sending the last line */ |
| 920 | pos = ftell(stream); |
Holger Hans Peter Freyther | 4c11d0b | 2014-04-04 11:48:32 +0200 | [diff] [blame] | 921 | |
| 922 | /* Did ftell fail? Then we are at the end for sure */ |
| 923 | if (pos < 0) |
| 924 | return 1; |
| 925 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 926 | if (!fgets(next_seg_buf, sizeof(next_seg_buf)-2, stream)) { |
Harald Welte | ad13b57 | 2016-11-26 14:11:16 +0100 | [diff] [blame] | 927 | int rc = fseek(stream, pos, SEEK_SET); |
| 928 | if (rc < 0) |
| 929 | return rc; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 930 | return 1; |
| 931 | } |
| 932 | |
| 933 | fseek(stream, pos, SEEK_SET); |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | /* 6.2.2 / 8.3.2 Load Data Segment */ |
| 938 | static int sw_load_segment(struct abis_nm_sw *sw) |
| 939 | { |
| 940 | struct abis_om_hdr *oh; |
| 941 | struct msgb *msg = nm_msgb_alloc(); |
| 942 | char seg_buf[256]; |
| 943 | char *line_buf = seg_buf+2; |
| 944 | unsigned char *tlv; |
Harald Welte | d198978 | 2011-07-16 13:03:29 +0200 | [diff] [blame] | 945 | int len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 946 | |
| 947 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 948 | |
| 949 | switch (sw->bts->type) { |
| 950 | case GSM_BTS_TYPE_BS11: |
| 951 | if (fgets(line_buf, sizeof(seg_buf)-2, sw->stream) == NULL) { |
| 952 | perror("fgets reading segment"); |
| 953 | return -EINVAL; |
| 954 | } |
| 955 | seg_buf[0] = 0x00; |
| 956 | |
| 957 | /* check if we're sending the last line */ |
| 958 | sw->last_seg = is_last_line(sw->stream); |
| 959 | if (sw->last_seg) |
| 960 | seg_buf[1] = 0; |
| 961 | else |
| 962 | seg_buf[1] = 1 + sw->seg_in_window++; |
| 963 | |
| 964 | len = strlen(line_buf) + 2; |
| 965 | tlv = msgb_put(msg, TLV_GROSS_LEN(len)); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 966 | tlv_put(tlv, NM_ATT_BS11_FILE_DATA, len, (uint8_t *)seg_buf); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 967 | /* BS11 wants CR + LF in excess of the TLV length !?! */ |
| 968 | tlv[1] -= 2; |
| 969 | |
| 970 | /* we only now know the exact length for the OM hdr */ |
| 971 | len = strlen(line_buf)+2; |
| 972 | break; |
Holger Hans Peter Freyther | b5f5448 | 2009-12-28 10:04:26 +0100 | [diff] [blame] | 973 | case GSM_BTS_TYPE_NANOBTS: { |
Pablo Neira Ayuso | b1d5a69 | 2011-05-07 12:12:48 +0200 | [diff] [blame] | 974 | osmo_static_assert(sizeof(seg_buf) >= IPACC_SEGMENT_SIZE, buffer_big_enough); |
Holger Hans Peter Freyther | b5f5448 | 2009-12-28 10:04:26 +0100 | [diff] [blame] | 975 | len = read(sw->fd, &seg_buf, IPACC_SEGMENT_SIZE); |
| 976 | if (len < 0) { |
| 977 | perror("read failed"); |
| 978 | return -EINVAL; |
| 979 | } |
| 980 | |
| 981 | if (len != IPACC_SEGMENT_SIZE) |
| 982 | sw->last_seg = 1; |
| 983 | |
Holger Hans Peter Freyther | 679a2eb | 2009-12-28 11:28:51 +0100 | [diff] [blame] | 984 | ++sw->seg_in_window; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 985 | msgb_tl16v_put(msg, NM_ATT_IPACC_FILE_DATA, len, (const uint8_t *) seg_buf); |
Holger Hans Peter Freyther | b5f5448 | 2009-12-28 10:04:26 +0100 | [diff] [blame] | 986 | len += 3; |
| 987 | break; |
| 988 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 989 | default: |
Holger Hans Peter Freyther | f8ea617 | 2009-12-28 09:21:18 +0100 | [diff] [blame] | 990 | LOGP(DNM, LOGL_ERROR, "sw_load_segment needs implementation for the BTS.\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 991 | /* FIXME: Other BTS types */ |
| 992 | return -1; |
| 993 | } |
| 994 | |
| 995 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_SEG, sw->obj_class, |
| 996 | sw->obj_instance[0], sw->obj_instance[1], |
| 997 | sw->obj_instance[2]); |
| 998 | |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 999 | return abis_nm_sendmsg_direct(sw->bts, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | /* 6.2.4 / 8.3.4 Load Data End */ |
| 1003 | static int sw_load_end(struct abis_nm_sw *sw) |
| 1004 | { |
| 1005 | struct abis_om_hdr *oh; |
| 1006 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1007 | uint8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1008 | |
| 1009 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1010 | fill_om_fom_hdr(oh, len, NM_MT_LOAD_END, sw->obj_class, |
| 1011 | sw->obj_instance[0], sw->obj_instance[1], |
| 1012 | sw->obj_instance[2]); |
| 1013 | |
Holger Hans Peter Freyther | d617f56 | 2009-12-30 09:23:48 +0100 | [diff] [blame] | 1014 | sw_add_file_id_and_ver(sw, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1015 | return abis_nm_sendmsg(sw->bts, msg); |
| 1016 | } |
| 1017 | |
| 1018 | /* Activate the specified software into the BTS */ |
| 1019 | static int sw_activate(struct abis_nm_sw *sw) |
| 1020 | { |
| 1021 | struct abis_om_hdr *oh; |
| 1022 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1023 | uint8_t len = 2*2 + sw->file_id_len + sw->file_version_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1024 | |
| 1025 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1026 | fill_om_fom_hdr(oh, len, NM_MT_ACTIVATE_SW, sw->obj_class, |
| 1027 | sw->obj_instance[0], sw->obj_instance[1], |
| 1028 | sw->obj_instance[2]); |
| 1029 | |
| 1030 | /* FIXME: this is BS11 specific format */ |
| 1031 | msgb_tlv_put(msg, NM_ATT_FILE_ID, sw->file_id_len, sw->file_id); |
| 1032 | msgb_tlv_put(msg, NM_ATT_FILE_VERSION, sw->file_version_len, |
| 1033 | sw->file_version); |
| 1034 | |
| 1035 | return abis_nm_sendmsg(sw->bts, msg); |
| 1036 | } |
| 1037 | |
Holger Hans Peter Freyther | a3ae06b | 2009-12-28 07:28:43 +0100 | [diff] [blame] | 1038 | struct sdp_firmware { |
| 1039 | char magic[4]; |
| 1040 | char more_magic[4]; |
| 1041 | unsigned int header_length; |
| 1042 | unsigned int file_length; |
| 1043 | } __attribute__ ((packed)); |
| 1044 | |
Holger Hans Peter Freyther | b5c03d3 | 2009-12-23 08:06:31 +0100 | [diff] [blame] | 1045 | static int parse_sdp_header(struct abis_nm_sw *sw) |
| 1046 | { |
Holger Hans Peter Freyther | a3ae06b | 2009-12-28 07:28:43 +0100 | [diff] [blame] | 1047 | struct sdp_firmware firmware_header; |
| 1048 | int rc; |
| 1049 | struct stat stat; |
| 1050 | |
| 1051 | rc = read(sw->fd, &firmware_header, sizeof(firmware_header)); |
| 1052 | if (rc != sizeof(firmware_header)) { |
| 1053 | LOGP(DNM, LOGL_ERROR, "Could not read SDP file header.\n"); |
| 1054 | return -1; |
| 1055 | } |
| 1056 | |
| 1057 | if (strncmp(firmware_header.magic, " SDP", 4) != 0) { |
| 1058 | LOGP(DNM, LOGL_ERROR, "The magic number1 is wrong.\n"); |
| 1059 | return -1; |
| 1060 | } |
| 1061 | |
| 1062 | if (firmware_header.more_magic[0] != 0x10 || |
| 1063 | firmware_header.more_magic[1] != 0x02 || |
| 1064 | firmware_header.more_magic[2] != 0x00 || |
| 1065 | firmware_header.more_magic[3] != 0x00) { |
| 1066 | LOGP(DNM, LOGL_ERROR, "The more magic number is wrong.\n"); |
| 1067 | return -1; |
| 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | if (fstat(sw->fd, &stat) == -1) { |
| 1072 | LOGP(DNM, LOGL_ERROR, "Could not stat the file.\n"); |
| 1073 | return -1; |
| 1074 | } |
| 1075 | |
| 1076 | if (ntohl(firmware_header.file_length) != stat.st_size) { |
| 1077 | LOGP(DNM, LOGL_ERROR, "The filesizes do not match.\n"); |
| 1078 | return -1; |
| 1079 | } |
| 1080 | |
| 1081 | /* go back to the start as we checked the whole filesize.. */ |
| 1082 | lseek(sw->fd, 0l, SEEK_SET); |
| 1083 | LOGP(DNM, LOGL_NOTICE, "The ipaccess SDP header is not fully understood.\n" |
| 1084 | "There might be checksums in the file that are not\n" |
| 1085 | "verified and incomplete firmware might be flashed.\n" |
| 1086 | "There is absolutely no WARRANTY that flashing will\n" |
| 1087 | "work.\n"); |
| 1088 | return 0; |
Holger Hans Peter Freyther | b5c03d3 | 2009-12-23 08:06:31 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1091 | static int sw_open_file(struct abis_nm_sw *sw, const char *fname) |
| 1092 | { |
| 1093 | char file_id[12+1]; |
| 1094 | char file_version[80+1]; |
| 1095 | int rc; |
| 1096 | |
| 1097 | sw->fd = open(fname, O_RDONLY); |
| 1098 | if (sw->fd < 0) |
| 1099 | return sw->fd; |
| 1100 | |
| 1101 | switch (sw->bts->type) { |
| 1102 | case GSM_BTS_TYPE_BS11: |
| 1103 | sw->stream = fdopen(sw->fd, "r"); |
| 1104 | if (!sw->stream) { |
| 1105 | perror("fdopen"); |
| 1106 | return -1; |
| 1107 | } |
| 1108 | /* read first line and parse file ID and VERSION */ |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 1109 | rc = fscanf(sw->stream, "@(#)%12s:%80s\r\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1110 | file_id, file_version); |
| 1111 | if (rc != 2) { |
| 1112 | perror("parsing header line of software file"); |
| 1113 | return -1; |
| 1114 | } |
| 1115 | strcpy((char *)sw->file_id, file_id); |
| 1116 | sw->file_id_len = strlen(file_id); |
| 1117 | strcpy((char *)sw->file_version, file_version); |
| 1118 | sw->file_version_len = strlen(file_version); |
| 1119 | /* rewind to start of file */ |
| 1120 | rewind(sw->stream); |
| 1121 | break; |
Holger Hans Peter Freyther | dfdced0 | 2009-12-23 07:26:57 +0100 | [diff] [blame] | 1122 | case GSM_BTS_TYPE_NANOBTS: |
Holger Hans Peter Freyther | dfdced0 | 2009-12-23 07:26:57 +0100 | [diff] [blame] | 1123 | /* TODO: extract that from the filename or content */ |
Holger Hans Peter Freyther | b5c03d3 | 2009-12-23 08:06:31 +0100 | [diff] [blame] | 1124 | rc = parse_sdp_header(sw); |
| 1125 | if (rc < 0) { |
| 1126 | fprintf(stderr, "Could not parse the ipaccess SDP header\n"); |
| 1127 | return -1; |
| 1128 | } |
Holger Hans Peter Freyther | 3890700 | 2009-12-28 09:02:41 +0100 | [diff] [blame] | 1129 | |
| 1130 | strcpy((char *)sw->file_id, "id"); |
| 1131 | sw->file_id_len = 3; |
| 1132 | strcpy((char *)sw->file_version, "version"); |
| 1133 | sw->file_version_len = 8; |
Holger Hans Peter Freyther | dfdced0 | 2009-12-23 07:26:57 +0100 | [diff] [blame] | 1134 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1135 | default: |
| 1136 | /* We don't know how to treat them yet */ |
| 1137 | close(sw->fd); |
| 1138 | return -EINVAL; |
| 1139 | } |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | static void sw_close_file(struct abis_nm_sw *sw) |
| 1145 | { |
| 1146 | switch (sw->bts->type) { |
| 1147 | case GSM_BTS_TYPE_BS11: |
| 1148 | fclose(sw->stream); |
| 1149 | break; |
| 1150 | default: |
| 1151 | close(sw->fd); |
| 1152 | break; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | /* Fill the window */ |
| 1157 | static int sw_fill_window(struct abis_nm_sw *sw) |
| 1158 | { |
| 1159 | int rc; |
| 1160 | |
| 1161 | while (sw->seg_in_window < sw->window_size) { |
| 1162 | rc = sw_load_segment(sw); |
| 1163 | if (rc < 0) |
| 1164 | return rc; |
| 1165 | if (sw->last_seg) |
| 1166 | break; |
| 1167 | } |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | /* callback function from abis_nm_rcvmsg() handler */ |
| 1172 | static int abis_nm_rcvmsg_sw(struct msgb *mb) |
| 1173 | { |
| 1174 | struct abis_om_fom_hdr *foh = msgb_l3(mb); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1175 | struct e1inp_sign_link *sign_link = mb->dst; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1176 | int rc = -1; |
| 1177 | struct abis_nm_sw *sw = &g_sw; |
| 1178 | enum sw_state old_state = sw->state; |
| 1179 | |
| 1180 | //DEBUGP(DNM, "state %u, NM MT 0x%02x\n", sw->state, foh->msg_type); |
| 1181 | |
| 1182 | switch (sw->state) { |
| 1183 | case SW_STATE_WAIT_INITACK: |
| 1184 | switch (foh->msg_type) { |
| 1185 | case NM_MT_LOAD_INIT_ACK: |
| 1186 | /* fill window with segments */ |
| 1187 | if (sw->cbfn) |
| 1188 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1189 | NM_MT_LOAD_INIT_ACK, mb, |
| 1190 | sw->cb_data, NULL); |
| 1191 | rc = sw_fill_window(sw); |
| 1192 | sw->state = SW_STATE_WAIT_SEGACK; |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1193 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1194 | break; |
| 1195 | case NM_MT_LOAD_INIT_NACK: |
| 1196 | if (sw->forced) { |
| 1197 | DEBUGP(DNM, "FORCED: Ignoring Software Load " |
| 1198 | "Init NACK\n"); |
| 1199 | if (sw->cbfn) |
| 1200 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1201 | NM_MT_LOAD_INIT_ACK, mb, |
| 1202 | sw->cb_data, NULL); |
| 1203 | rc = sw_fill_window(sw); |
| 1204 | sw->state = SW_STATE_WAIT_SEGACK; |
| 1205 | } else { |
| 1206 | DEBUGP(DNM, "Software Load Init NACK\n"); |
| 1207 | /* FIXME: cause */ |
| 1208 | if (sw->cbfn) |
| 1209 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1210 | NM_MT_LOAD_INIT_NACK, mb, |
| 1211 | sw->cb_data, NULL); |
| 1212 | sw->state = SW_STATE_ERROR; |
| 1213 | } |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1214 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1215 | break; |
| 1216 | } |
| 1217 | break; |
| 1218 | case SW_STATE_WAIT_SEGACK: |
| 1219 | switch (foh->msg_type) { |
| 1220 | case NM_MT_LOAD_SEG_ACK: |
| 1221 | if (sw->cbfn) |
| 1222 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1223 | NM_MT_LOAD_SEG_ACK, mb, |
| 1224 | sw->cb_data, NULL); |
| 1225 | sw->seg_in_window = 0; |
| 1226 | if (!sw->last_seg) { |
| 1227 | /* fill window with more segments */ |
| 1228 | rc = sw_fill_window(sw); |
| 1229 | sw->state = SW_STATE_WAIT_SEGACK; |
| 1230 | } else { |
| 1231 | /* end the transfer */ |
| 1232 | sw->state = SW_STATE_WAIT_ENDACK; |
| 1233 | rc = sw_load_end(sw); |
| 1234 | } |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1235 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1236 | break; |
Holger Hans Peter Freyther | 61f814d | 2009-12-28 12:23:02 +0100 | [diff] [blame] | 1237 | case NM_MT_LOAD_ABORT: |
| 1238 | if (sw->cbfn) |
| 1239 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1240 | NM_MT_LOAD_ABORT, mb, |
| 1241 | sw->cb_data, NULL); |
| 1242 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1243 | } |
| 1244 | break; |
| 1245 | case SW_STATE_WAIT_ENDACK: |
| 1246 | switch (foh->msg_type) { |
| 1247 | case NM_MT_LOAD_END_ACK: |
| 1248 | sw_close_file(sw); |
| 1249 | DEBUGP(DNM, "Software Load End (BTS %u)\n", |
| 1250 | sw->bts->nr); |
| 1251 | sw->state = SW_STATE_NONE; |
| 1252 | if (sw->cbfn) |
| 1253 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1254 | NM_MT_LOAD_END_ACK, mb, |
| 1255 | sw->cb_data, NULL); |
Holger Hans Peter Freyther | 9930072 | 2009-12-28 11:48:12 +0100 | [diff] [blame] | 1256 | rc = 0; |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1257 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1258 | break; |
| 1259 | case NM_MT_LOAD_END_NACK: |
| 1260 | if (sw->forced) { |
| 1261 | DEBUGP(DNM, "FORCED: Ignoring Software Load" |
| 1262 | "End NACK\n"); |
| 1263 | sw->state = SW_STATE_NONE; |
| 1264 | if (sw->cbfn) |
| 1265 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1266 | NM_MT_LOAD_END_ACK, mb, |
| 1267 | sw->cb_data, NULL); |
| 1268 | } else { |
| 1269 | DEBUGP(DNM, "Software Load End NACK\n"); |
| 1270 | /* FIXME: cause */ |
| 1271 | sw->state = SW_STATE_ERROR; |
| 1272 | if (sw->cbfn) |
| 1273 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1274 | NM_MT_LOAD_END_NACK, mb, |
| 1275 | sw->cb_data, NULL); |
| 1276 | } |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1277 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1278 | break; |
| 1279 | } |
| 1280 | case SW_STATE_WAIT_ACTACK: |
| 1281 | switch (foh->msg_type) { |
| 1282 | case NM_MT_ACTIVATE_SW_ACK: |
| 1283 | /* we're done */ |
| 1284 | DEBUGP(DNM, "Activate Software DONE!\n"); |
| 1285 | sw->state = SW_STATE_NONE; |
| 1286 | rc = 0; |
| 1287 | if (sw->cbfn) |
| 1288 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1289 | NM_MT_ACTIVATE_SW_ACK, mb, |
| 1290 | sw->cb_data, NULL); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1291 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1292 | break; |
| 1293 | case NM_MT_ACTIVATE_SW_NACK: |
| 1294 | DEBUGP(DNM, "Activate Software NACK\n"); |
| 1295 | /* FIXME: cause */ |
| 1296 | sw->state = SW_STATE_ERROR; |
| 1297 | if (sw->cbfn) |
| 1298 | sw->cbfn(GSM_HOOK_NM_SWLOAD, |
| 1299 | NM_MT_ACTIVATE_SW_NACK, mb, |
| 1300 | sw->cb_data, NULL); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 1301 | abis_nm_queue_send_next(sign_link->trx->bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1302 | break; |
| 1303 | } |
| 1304 | case SW_STATE_NONE: |
| 1305 | switch (foh->msg_type) { |
| 1306 | case NM_MT_ACTIVATE_SW_ACK: |
| 1307 | rc = 0; |
| 1308 | break; |
| 1309 | } |
| 1310 | break; |
| 1311 | case SW_STATE_ERROR: |
| 1312 | break; |
| 1313 | } |
| 1314 | |
| 1315 | if (rc) |
| 1316 | DEBUGP(DNM, "unexpected NM MT 0x%02x in state %u -> %u\n", |
| 1317 | foh->msg_type, old_state, sw->state); |
| 1318 | |
| 1319 | return rc; |
| 1320 | } |
| 1321 | |
| 1322 | /* Load the specified software into the BTS */ |
Holger Hans Peter Freyther | 2b4083a | 2010-05-12 23:51:46 +0800 | [diff] [blame] | 1323 | int abis_nm_software_load(struct gsm_bts *bts, int trx_nr, const char *fname, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1324 | uint8_t win_size, int forced, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1325 | gsm_cbfn *cbfn, void *cb_data) |
| 1326 | { |
| 1327 | struct abis_nm_sw *sw = &g_sw; |
| 1328 | int rc; |
| 1329 | |
| 1330 | DEBUGP(DNM, "Software Load (BTS %u, File \"%s\")\n", |
| 1331 | bts->nr, fname); |
| 1332 | |
| 1333 | if (sw->state != SW_STATE_NONE) |
| 1334 | return -EBUSY; |
| 1335 | |
| 1336 | sw->bts = bts; |
Holger Hans Peter Freyther | 2b4083a | 2010-05-12 23:51:46 +0800 | [diff] [blame] | 1337 | sw->trx_nr = trx_nr; |
Holger Hans Peter Freyther | 3890700 | 2009-12-28 09:02:41 +0100 | [diff] [blame] | 1338 | |
| 1339 | switch (bts->type) { |
| 1340 | case GSM_BTS_TYPE_BS11: |
| 1341 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1342 | sw->obj_instance[0] = 0xff; |
| 1343 | sw->obj_instance[1] = 0xff; |
| 1344 | sw->obj_instance[2] = 0xff; |
| 1345 | break; |
| 1346 | case GSM_BTS_TYPE_NANOBTS: |
| 1347 | sw->obj_class = NM_OC_BASEB_TRANSC; |
Holger Hans Peter Freyther | 2b4083a | 2010-05-12 23:51:46 +0800 | [diff] [blame] | 1348 | sw->obj_instance[0] = sw->bts->nr; |
| 1349 | sw->obj_instance[1] = sw->trx_nr; |
Holger Hans Peter Freyther | 3890700 | 2009-12-28 09:02:41 +0100 | [diff] [blame] | 1350 | sw->obj_instance[2] = 0xff; |
| 1351 | break; |
| 1352 | case GSM_BTS_TYPE_UNKNOWN: |
| 1353 | default: |
| 1354 | LOGPC(DNM, LOGL_ERROR, "Software Load not properly implemented.\n"); |
| 1355 | return -1; |
| 1356 | break; |
| 1357 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1358 | sw->window_size = win_size; |
| 1359 | sw->state = SW_STATE_WAIT_INITACK; |
| 1360 | sw->cbfn = cbfn; |
| 1361 | sw->cb_data = cb_data; |
| 1362 | sw->forced = forced; |
| 1363 | |
| 1364 | rc = sw_open_file(sw, fname); |
| 1365 | if (rc < 0) { |
| 1366 | sw->state = SW_STATE_NONE; |
| 1367 | return rc; |
| 1368 | } |
| 1369 | |
| 1370 | return sw_load_init(sw); |
| 1371 | } |
| 1372 | |
| 1373 | int abis_nm_software_load_status(struct gsm_bts *bts) |
| 1374 | { |
| 1375 | struct abis_nm_sw *sw = &g_sw; |
| 1376 | struct stat st; |
| 1377 | int rc, percent; |
| 1378 | |
| 1379 | rc = fstat(sw->fd, &st); |
| 1380 | if (rc < 0) { |
| 1381 | perror("ERROR during stat"); |
| 1382 | return rc; |
| 1383 | } |
| 1384 | |
Holger Hans Peter Freyther | 876a06b | 2009-12-28 10:16:54 +0100 | [diff] [blame] | 1385 | if (sw->stream) |
| 1386 | percent = (ftell(sw->stream) * 100) / st.st_size; |
| 1387 | else |
| 1388 | percent = (lseek(sw->fd, 0, SEEK_CUR) * 100) / st.st_size; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1389 | return percent; |
| 1390 | } |
| 1391 | |
| 1392 | /* Activate the specified software into the BTS */ |
| 1393 | int abis_nm_software_activate(struct gsm_bts *bts, const char *fname, |
| 1394 | gsm_cbfn *cbfn, void *cb_data) |
| 1395 | { |
| 1396 | struct abis_nm_sw *sw = &g_sw; |
| 1397 | int rc; |
| 1398 | |
| 1399 | DEBUGP(DNM, "Activating Software (BTS %u, File \"%s\")\n", |
| 1400 | bts->nr, fname); |
| 1401 | |
| 1402 | if (sw->state != SW_STATE_NONE) |
| 1403 | return -EBUSY; |
| 1404 | |
| 1405 | sw->bts = bts; |
| 1406 | sw->obj_class = NM_OC_SITE_MANAGER; |
| 1407 | sw->obj_instance[0] = 0xff; |
| 1408 | sw->obj_instance[1] = 0xff; |
| 1409 | sw->obj_instance[2] = 0xff; |
| 1410 | sw->state = SW_STATE_WAIT_ACTACK; |
| 1411 | sw->cbfn = cbfn; |
| 1412 | sw->cb_data = cb_data; |
| 1413 | |
| 1414 | /* Open the file in order to fill some sw struct members */ |
| 1415 | rc = sw_open_file(sw, fname); |
| 1416 | if (rc < 0) { |
| 1417 | sw->state = SW_STATE_NONE; |
| 1418 | return rc; |
| 1419 | } |
| 1420 | sw_close_file(sw); |
| 1421 | |
| 1422 | return sw_activate(sw); |
| 1423 | } |
| 1424 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1425 | static void fill_nm_channel(struct abis_nm_channel *ch, uint8_t bts_port, |
| 1426 | uint8_t ts_nr, uint8_t subslot_nr) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1427 | { |
| 1428 | ch->attrib = NM_ATT_ABIS_CHANNEL; |
| 1429 | ch->bts_port = bts_port; |
| 1430 | ch->timeslot = ts_nr; |
| 1431 | ch->subslot = subslot_nr; |
| 1432 | } |
| 1433 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1434 | int abis_nm_establish_tei(struct gsm_bts *bts, uint8_t trx_nr, |
| 1435 | uint8_t e1_port, uint8_t e1_timeslot, uint8_t e1_subslot, |
| 1436 | uint8_t tei) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1437 | { |
| 1438 | struct abis_om_hdr *oh; |
| 1439 | struct abis_nm_channel *ch; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1440 | uint8_t len = sizeof(*ch) + 2; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1441 | struct msgb *msg = nm_msgb_alloc(); |
| 1442 | |
| 1443 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1444 | fill_om_fom_hdr(oh, len, NM_MT_ESTABLISH_TEI, NM_OC_RADIO_CARRIER, |
| 1445 | bts->bts_nr, trx_nr, 0xff); |
| 1446 | |
| 1447 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
| 1448 | |
| 1449 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1450 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1451 | |
| 1452 | return abis_nm_sendmsg(bts, msg); |
| 1453 | } |
| 1454 | |
| 1455 | /* connect signalling of one (BTS,TRX) to a particular timeslot on the E1 */ |
| 1456 | int abis_nm_conn_terr_sign(struct gsm_bts_trx *trx, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1457 | uint8_t e1_port, uint8_t e1_timeslot, uint8_t e1_subslot) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1458 | { |
| 1459 | struct gsm_bts *bts = trx->bts; |
| 1460 | struct abis_om_hdr *oh; |
| 1461 | struct abis_nm_channel *ch; |
| 1462 | struct msgb *msg = nm_msgb_alloc(); |
| 1463 | |
| 1464 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1465 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_SIGN, |
| 1466 | NM_OC_RADIO_CARRIER, bts->bts_nr, trx->nr, 0xff); |
| 1467 | |
| 1468 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1469 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1470 | |
| 1471 | return abis_nm_sendmsg(bts, msg); |
| 1472 | } |
| 1473 | |
| 1474 | #if 0 |
| 1475 | int abis_nm_disc_terr_sign(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1476 | struct abis_nm_abis_channel *chan) |
| 1477 | { |
| 1478 | } |
| 1479 | #endif |
| 1480 | |
| 1481 | int abis_nm_conn_terr_traf(struct gsm_bts_trx_ts *ts, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1482 | uint8_t e1_port, uint8_t e1_timeslot, |
| 1483 | uint8_t e1_subslot) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1484 | { |
| 1485 | struct gsm_bts *bts = ts->trx->bts; |
| 1486 | struct abis_om_hdr *oh; |
| 1487 | struct abis_nm_channel *ch; |
| 1488 | struct msgb *msg = nm_msgb_alloc(); |
| 1489 | |
| 1490 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1491 | fill_om_fom_hdr(oh, sizeof(*ch), NM_MT_CONN_TERR_TRAF, |
| 1492 | NM_OC_CHANNEL, bts->bts_nr, ts->trx->nr, ts->nr); |
| 1493 | |
| 1494 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 1495 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 1496 | |
| 1497 | DEBUGP(DNM, "CONNECT TERR TRAF Um=%s E1=(%u,%u,%u)\n", |
| 1498 | gsm_ts_name(ts), |
| 1499 | e1_port, e1_timeslot, e1_subslot); |
| 1500 | |
| 1501 | return abis_nm_sendmsg(bts, msg); |
| 1502 | } |
| 1503 | |
| 1504 | #if 0 |
| 1505 | int abis_nm_disc_terr_traf(struct abis_nm_h *h, struct abis_om_obj_inst *inst, |
| 1506 | struct abis_nm_abis_channel *chan, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1507 | uint8_t subchan) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1508 | { |
| 1509 | } |
| 1510 | #endif |
| 1511 | |
Harald Welte | 2ec3a7b | 2012-08-14 19:15:57 +0200 | [diff] [blame] | 1512 | /* Chapter 8.11.1 */ |
| 1513 | int abis_nm_get_attr(struct gsm_bts *bts, uint8_t obj_class, |
| 1514 | uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, |
| 1515 | uint8_t *attr, uint8_t attr_len) |
| 1516 | { |
| 1517 | struct abis_om_hdr *oh; |
| 1518 | struct msgb *msg = nm_msgb_alloc(); |
Harald Welte | 2ec3a7b | 2012-08-14 19:15:57 +0200 | [diff] [blame] | 1519 | |
| 1520 | DEBUGP(DNM, "Get Attr (bts=%d)\n", bts->nr); |
| 1521 | |
| 1522 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1523 | fill_om_fom_hdr(oh, attr_len, NM_MT_GET_ATTR, obj_class, |
| 1524 | bts_nr, trx_nr, ts_nr); |
| 1525 | msgb_tl16v_put(msg, NM_ATT_LIST_REQ_ATTR, attr_len, attr); |
| 1526 | |
| 1527 | return abis_nm_sendmsg(bts, msg); |
| 1528 | } |
| 1529 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1530 | /* Chapter 8.6.1 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1531 | int abis_nm_set_bts_attr(struct gsm_bts *bts, uint8_t *attr, int attr_len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1532 | { |
| 1533 | struct abis_om_hdr *oh; |
| 1534 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1535 | uint8_t *cur; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1536 | |
| 1537 | DEBUGP(DNM, "Set BTS Attr (bts=%d)\n", bts->nr); |
| 1538 | |
| 1539 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1540 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_BTS_ATTR, NM_OC_BTS, bts->bts_nr, 0xff, 0xff); |
| 1541 | cur = msgb_put(msg, attr_len); |
| 1542 | memcpy(cur, attr, attr_len); |
| 1543 | |
| 1544 | return abis_nm_sendmsg(bts, msg); |
| 1545 | } |
| 1546 | |
| 1547 | /* Chapter 8.6.2 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1548 | int abis_nm_set_radio_attr(struct gsm_bts_trx *trx, uint8_t *attr, int attr_len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1549 | { |
| 1550 | struct abis_om_hdr *oh; |
| 1551 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1552 | uint8_t *cur; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1553 | |
| 1554 | DEBUGP(DNM, "Set TRX Attr (bts=%d,trx=%d)\n", trx->bts->nr, trx->nr); |
| 1555 | |
| 1556 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1557 | fill_om_fom_hdr(oh, attr_len, NM_MT_SET_RADIO_ATTR, NM_OC_RADIO_CARRIER, |
| 1558 | trx->bts->bts_nr, trx->nr, 0xff); |
| 1559 | cur = msgb_put(msg, attr_len); |
| 1560 | memcpy(cur, attr, attr_len); |
| 1561 | |
| 1562 | return abis_nm_sendmsg(trx->bts, msg); |
| 1563 | } |
| 1564 | |
Holger Hans Peter Freyther | 1f67232 | 2014-03-26 14:24:42 +0100 | [diff] [blame] | 1565 | int abis_nm_update_max_power_red(struct gsm_bts_trx *trx) |
| 1566 | { |
| 1567 | uint8_t attr[] = { NM_ATT_RF_MAXPOWR_R, trx->max_power_red / 2 }; |
| 1568 | return abis_nm_set_radio_attr(trx, attr, ARRAY_SIZE(attr)); |
| 1569 | } |
| 1570 | |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1571 | static int verify_chan_comb(struct gsm_bts_trx_ts *ts, uint8_t chan_comb, |
| 1572 | const char **reason) |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1573 | { |
| 1574 | int i; |
| 1575 | |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1576 | *reason = "Reason unknown"; |
| 1577 | |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1578 | /* As it turns out, the BS-11 has some very peculiar restrictions |
| 1579 | * on the channel combinations it allows */ |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1580 | switch (ts->trx->bts->type) { |
| 1581 | case GSM_BTS_TYPE_BS11: |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1582 | switch (chan_comb) { |
| 1583 | case NM_CHANC_TCHHalf: |
| 1584 | case NM_CHANC_TCHHalf2: |
Neels Hofmeyr | 5af6113 | 2016-07-14 03:09:56 +0200 | [diff] [blame] | 1585 | case NM_CHANC_OSMO_TCHFull_TCHHalf_PDCH: |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1586 | /* not supported */ |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1587 | *reason = "TCH/H is not supported."; |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1588 | return -EINVAL; |
| 1589 | case NM_CHANC_SDCCH: |
| 1590 | /* only one SDCCH/8 per TRX */ |
| 1591 | for (i = 0; i < TRX_NR_TS; i++) { |
| 1592 | if (i == ts->nr) |
| 1593 | continue; |
| 1594 | if (ts->trx->ts[i].nm_chan_comb == |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1595 | NM_CHANC_SDCCH) { |
| 1596 | *reason = "Only one SDCCH/8 per TRX allowed."; |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1597 | return -EINVAL; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1598 | } |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1599 | } |
| 1600 | /* not allowed for TS0 of BCCH-TRX */ |
| 1601 | if (ts->trx == ts->trx->bts->c0 && |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1602 | ts->nr == 0) { |
| 1603 | *reason = "SDCCH/8 must be on TS0."; |
| 1604 | return -EINVAL; |
| 1605 | } |
| 1606 | |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1607 | /* not on the same TRX that has a BCCH+SDCCH4 |
| 1608 | * combination */ |
Holger Hans Peter Freyther | fca3eb9 | 2013-01-08 19:30:14 +0100 | [diff] [blame] | 1609 | if (ts->trx != ts->trx->bts->c0 && |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1610 | (ts->trx->ts[0].nm_chan_comb == 5 || |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1611 | ts->trx->ts[0].nm_chan_comb == 8)) { |
| 1612 | *reason = "SDCCH/8 and BCCH must be on the same TRX."; |
| 1613 | return -EINVAL; |
| 1614 | } |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1615 | break; |
| 1616 | case NM_CHANC_mainBCCH: |
| 1617 | case NM_CHANC_BCCHComb: |
| 1618 | /* allowed only for TS0 of C0 */ |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1619 | if (ts->trx != ts->trx->bts->c0 || ts->nr != 0) { |
| 1620 | *reason = "Main BCCH must be on TS0."; |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1621 | return -EINVAL; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1622 | } |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1623 | break; |
| 1624 | case NM_CHANC_BCCH: |
| 1625 | /* allowed only for TS 2/4/6 of C0 */ |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1626 | if (ts->trx != ts->trx->bts->c0) { |
| 1627 | *reason = "BCCH must be on C0."; |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1628 | return -EINVAL; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1629 | } |
| 1630 | if (ts->nr != 2 && ts->nr != 4 && ts->nr != 6) { |
| 1631 | *reason = "BCCH must be on TS 2/4/6."; |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1632 | return -EINVAL; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1633 | } |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1634 | break; |
| 1635 | case 8: /* this is not like 08.58, but in fact |
| 1636 | * FCCH+SCH+BCCH+CCCH+SDCCH/4+SACCH/C4+CBCH */ |
| 1637 | /* FIXME: only one CBCH allowed per cell */ |
| 1638 | break; |
| 1639 | } |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1640 | break; |
| 1641 | case GSM_BTS_TYPE_NANOBTS: |
| 1642 | switch (ts->nr) { |
| 1643 | case 0: |
| 1644 | if (ts->trx->nr == 0) { |
| 1645 | /* only on TRX0 */ |
| 1646 | switch (chan_comb) { |
| 1647 | case NM_CHANC_BCCH: |
| 1648 | case NM_CHANC_mainBCCH: |
| 1649 | case NM_CHANC_BCCHComb: |
| 1650 | return 0; |
| 1651 | break; |
| 1652 | default: |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1653 | *reason = "TS0 of TRX0 must carry a BCCH."; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1654 | return -EINVAL; |
| 1655 | } |
| 1656 | } else { |
| 1657 | switch (chan_comb) { |
| 1658 | case NM_CHANC_TCHFull: |
| 1659 | case NM_CHANC_TCHHalf: |
| 1660 | case NM_CHANC_IPAC_TCHFull_TCHHalf: |
| 1661 | return 0; |
| 1662 | default: |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1663 | *reason = "TS0 must carry a TCH/F or TCH/H."; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1664 | return -EINVAL; |
| 1665 | } |
| 1666 | } |
| 1667 | break; |
| 1668 | case 1: |
| 1669 | if (ts->trx->nr == 0) { |
| 1670 | switch (chan_comb) { |
| 1671 | case NM_CHANC_SDCCH_CBCH: |
| 1672 | if (ts->trx->ts[0].nm_chan_comb == |
| 1673 | NM_CHANC_mainBCCH) |
| 1674 | return 0; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1675 | *reason = "TS0 must be the main BCCH for CBCH."; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1676 | return -EINVAL; |
| 1677 | case NM_CHANC_SDCCH: |
| 1678 | case NM_CHANC_TCHFull: |
| 1679 | case NM_CHANC_TCHHalf: |
| 1680 | case NM_CHANC_IPAC_TCHFull_TCHHalf: |
| 1681 | case NM_CHANC_IPAC_TCHFull_PDCH: |
Neels Hofmeyr | 5af6113 | 2016-07-14 03:09:56 +0200 | [diff] [blame] | 1682 | case NM_CHANC_OSMO_TCHFull_TCHHalf_PDCH: |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1683 | return 0; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1684 | default: |
| 1685 | *reason = "TS1 must carry a CBCH, SDCCH or TCH."; |
| 1686 | return -EINVAL; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1687 | } |
| 1688 | } else { |
| 1689 | switch (chan_comb) { |
| 1690 | case NM_CHANC_SDCCH: |
| 1691 | case NM_CHANC_TCHFull: |
| 1692 | case NM_CHANC_TCHHalf: |
| 1693 | case NM_CHANC_IPAC_TCHFull_TCHHalf: |
| 1694 | return 0; |
| 1695 | default: |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1696 | *reason = "TS1 must carry a SDCCH or TCH."; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1697 | return -EINVAL; |
| 1698 | } |
| 1699 | } |
| 1700 | break; |
| 1701 | case 2: |
| 1702 | case 3: |
| 1703 | case 4: |
| 1704 | case 5: |
| 1705 | case 6: |
| 1706 | case 7: |
| 1707 | switch (chan_comb) { |
| 1708 | case NM_CHANC_TCHFull: |
| 1709 | case NM_CHANC_TCHHalf: |
| 1710 | case NM_CHANC_IPAC_TCHFull_TCHHalf: |
| 1711 | return 0; |
| 1712 | case NM_CHANC_IPAC_PDCH: |
| 1713 | case NM_CHANC_IPAC_TCHFull_PDCH: |
Neels Hofmeyr | 5af6113 | 2016-07-14 03:09:56 +0200 | [diff] [blame] | 1714 | case NM_CHANC_OSMO_TCHFull_TCHHalf_PDCH: |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1715 | if (ts->trx->nr == 0) |
| 1716 | return 0; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1717 | else { |
| 1718 | *reason = "PDCH must be on TRX0."; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1719 | return -EINVAL; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1720 | } |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1721 | } |
| 1722 | break; |
| 1723 | } |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1724 | *reason = "Unknown combination"; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1725 | return -EINVAL; |
Max | abf3eb1 | 2017-03-23 12:01:07 +0100 | [diff] [blame] | 1726 | case GSM_BTS_TYPE_OSMOBTS: |
Harald Welte | 35ac0e4 | 2012-07-02 19:51:55 +0200 | [diff] [blame] | 1727 | /* no known restrictions */ |
| 1728 | return 0; |
Harald Welte | 76ba881 | 2009-12-02 02:45:23 +0530 | [diff] [blame] | 1729 | default: |
| 1730 | /* unknown BTS type */ |
| 1731 | return 0; |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1732 | } |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1736 | /* Chapter 8.6.3 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1737 | int abis_nm_set_channel_attr(struct gsm_bts_trx_ts *ts, uint8_t chan_comb) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1738 | { |
| 1739 | struct gsm_bts *bts = ts->trx->bts; |
| 1740 | struct abis_om_hdr *oh; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1741 | uint8_t zero = 0x00; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1742 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1743 | uint8_t len = 2 + 2; |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1744 | const char *reason = NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1745 | |
| 1746 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1747 | len += 4 + 2 + 2 + 3; |
| 1748 | |
| 1749 | DEBUGP(DNM, "Set Chan Attr %s\n", gsm_ts_name(ts)); |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1750 | if (verify_chan_comb(ts, chan_comb, &reason) < 0) { |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1751 | msgb_free(msg); |
Holger Hans Peter Freyther | 8bb8e80 | 2012-09-17 15:49:16 +0200 | [diff] [blame] | 1752 | LOGP(DNM, LOGL_ERROR, |
| 1753 | "Invalid Channel Combination %d on %s. Reason: %s\n", |
| 1754 | chan_comb, gsm_ts_name(ts), reason); |
Harald Welte | f2eb278 | 2009-08-09 21:49:48 +0200 | [diff] [blame] | 1755 | return -EINVAL; |
| 1756 | } |
| 1757 | ts->nm_chan_comb = chan_comb; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1758 | |
| 1759 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1760 | fill_om_fom_hdr(oh, len, NM_MT_SET_CHAN_ATTR, |
| 1761 | NM_OC_CHANNEL, bts->bts_nr, |
| 1762 | ts->trx->nr, ts->nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1763 | msgb_tv_put(msg, NM_ATT_CHAN_COMB, chan_comb); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 1764 | if (ts->hopping.enabled) { |
| 1765 | unsigned int i; |
| 1766 | uint8_t *len; |
| 1767 | |
Harald Welte | 67104d1 | 2009-09-12 13:05:33 +0200 | [diff] [blame] | 1768 | msgb_tv_put(msg, NM_ATT_HSN, ts->hopping.hsn); |
| 1769 | msgb_tv_put(msg, NM_ATT_MAIO, ts->hopping.maio); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 1770 | |
| 1771 | /* build the ARFCN list */ |
| 1772 | msgb_put_u8(msg, NM_ATT_ARFCN_LIST); |
| 1773 | len = msgb_put(msg, 1); |
| 1774 | *len = 0; |
| 1775 | for (i = 0; i < ts->hopping.arfcns.data_len*8; i++) { |
| 1776 | if (bitvec_get_bit_pos(&ts->hopping.arfcns, i)) { |
| 1777 | msgb_put_u16(msg, i); |
laforge | dcc63bb | 2010-06-20 15:20:02 +0200 | [diff] [blame] | 1778 | /* At least BS-11 wants a TLV16 here */ |
| 1779 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1780 | *len += 1; |
| 1781 | else |
| 1782 | *len += sizeof(uint16_t); |
Harald Welte | a42a93f | 2010-06-14 22:26:10 +0200 | [diff] [blame] | 1783 | } |
| 1784 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1785 | } |
Harald Welte | 025e6c9 | 2014-01-19 17:18:21 +0100 | [diff] [blame] | 1786 | msgb_tv_put(msg, NM_ATT_TSC, gsm_ts_tsc(ts)); /* training sequence */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1787 | if (bts->type == GSM_BTS_TYPE_BS11) |
| 1788 | msgb_tlv_put(msg, 0x59, 1, &zero); |
| 1789 | |
| 1790 | return abis_nm_sendmsg(bts, msg); |
| 1791 | } |
| 1792 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1793 | int abis_nm_sw_act_req_ack(struct gsm_bts *bts, uint8_t obj_class, uint8_t i1, |
| 1794 | uint8_t i2, uint8_t i3, int nack, uint8_t *attr, int att_len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1795 | { |
| 1796 | struct abis_om_hdr *oh; |
| 1797 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1798 | uint8_t msgtype = NM_MT_SW_ACT_REQ_ACK; |
| 1799 | uint8_t len = att_len; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1800 | |
| 1801 | if (nack) { |
| 1802 | len += 2; |
| 1803 | msgtype = NM_MT_SW_ACT_REQ_NACK; |
| 1804 | } |
| 1805 | |
| 1806 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1807 | fill_om_fom_hdr(oh, att_len, msgtype, obj_class, i1, i2, i3); |
| 1808 | |
| 1809 | if (attr) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1810 | uint8_t *ptr = msgb_put(msg, att_len); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1811 | memcpy(ptr, attr, att_len); |
| 1812 | } |
| 1813 | if (nack) |
| 1814 | msgb_tv_put(msg, NM_ATT_NACK_CAUSES, NM_NACK_OBJCLASS_NOTSUPP); |
| 1815 | |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 1816 | return abis_nm_sendmsg_direct(bts, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1817 | } |
| 1818 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1819 | int abis_nm_raw_msg(struct gsm_bts *bts, int len, uint8_t *rawmsg) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1820 | { |
| 1821 | struct msgb *msg = nm_msgb_alloc(); |
| 1822 | struct abis_om_hdr *oh; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1823 | uint8_t *data; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1824 | |
| 1825 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 1826 | fill_om_hdr(oh, len); |
| 1827 | data = msgb_put(msg, len); |
| 1828 | memcpy(data, rawmsg, len); |
| 1829 | |
| 1830 | return abis_nm_sendmsg(bts, msg); |
| 1831 | } |
| 1832 | |
| 1833 | /* Siemens specific commands */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1834 | static int __simple_cmd(struct gsm_bts *bts, uint8_t msg_type) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1835 | { |
| 1836 | struct abis_om_hdr *oh; |
| 1837 | struct msgb *msg = nm_msgb_alloc(); |
| 1838 | |
| 1839 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1840 | fill_om_fom_hdr(oh, 0, msg_type, NM_OC_SITE_MANAGER, |
| 1841 | 0xff, 0xff, 0xff); |
| 1842 | |
| 1843 | return abis_nm_sendmsg(bts, msg); |
| 1844 | } |
| 1845 | |
| 1846 | /* Chapter 8.9.2 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1847 | int abis_nm_opstart(struct gsm_bts *bts, uint8_t obj_class, uint8_t i0, uint8_t i1, uint8_t i2) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1848 | { |
| 1849 | struct abis_om_hdr *oh; |
Holger Hans Peter Freyther | ffd0f22 | 2014-04-04 12:56:34 +0200 | [diff] [blame] | 1850 | struct abis_om_fom_hdr *foh; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1851 | struct msgb *msg = nm_msgb_alloc(); |
| 1852 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1853 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
Holger Hans Peter Freyther | ffd0f22 | 2014-04-04 12:56:34 +0200 | [diff] [blame] | 1854 | foh = fill_om_fom_hdr(oh, 0, NM_MT_OPSTART, obj_class, i0, i1, i2); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1855 | |
Holger Hans Peter Freyther | ffd0f22 | 2014-04-04 12:56:34 +0200 | [diff] [blame] | 1856 | abis_nm_debugp_foh(DNM, foh); |
Harald Welte | b7284a9 | 2009-10-20 09:56:18 +0200 | [diff] [blame] | 1857 | DEBUGPC(DNM, "Sending OPSTART\n"); |
| 1858 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1859 | return abis_nm_sendmsg(bts, msg); |
| 1860 | } |
| 1861 | |
| 1862 | /* Chapter 8.8.5 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1863 | int abis_nm_chg_adm_state(struct gsm_bts *bts, uint8_t obj_class, uint8_t i0, |
| 1864 | uint8_t i1, uint8_t i2, enum abis_nm_adm_state adm_state) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1865 | { |
| 1866 | struct abis_om_hdr *oh; |
| 1867 | struct msgb *msg = nm_msgb_alloc(); |
| 1868 | |
| 1869 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1870 | fill_om_fom_hdr(oh, 2, NM_MT_CHG_ADM_STATE, obj_class, i0, i1, i2); |
| 1871 | msgb_tv_put(msg, NM_ATT_ADM_STATE, adm_state); |
| 1872 | |
| 1873 | return abis_nm_sendmsg(bts, msg); |
| 1874 | } |
| 1875 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1876 | int abis_nm_conn_mdrop_link(struct gsm_bts *bts, uint8_t e1_port0, uint8_t ts0, |
| 1877 | uint8_t e1_port1, uint8_t ts1) |
Harald Welte | 204317e | 2009-08-06 17:58:31 +0200 | [diff] [blame] | 1878 | { |
| 1879 | struct abis_om_hdr *oh; |
| 1880 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1881 | uint8_t *attr; |
Harald Welte | 204317e | 2009-08-06 17:58:31 +0200 | [diff] [blame] | 1882 | |
| 1883 | DEBUGP(DNM, "CONNECT MDROP LINK E1=(%u,%u) -> E1=(%u, %u)\n", |
| 1884 | e1_port0, ts0, e1_port1, ts1); |
| 1885 | |
| 1886 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1887 | fill_om_fom_hdr(oh, 6, NM_MT_CONN_MDROP_LINK, |
| 1888 | NM_OC_SITE_MANAGER, 0x00, 0x00, 0x00); |
| 1889 | |
| 1890 | attr = msgb_put(msg, 3); |
| 1891 | attr[0] = NM_ATT_MDROP_LINK; |
| 1892 | attr[1] = e1_port0; |
| 1893 | attr[2] = ts0; |
| 1894 | |
| 1895 | attr = msgb_put(msg, 3); |
| 1896 | attr[0] = NM_ATT_MDROP_NEXT; |
| 1897 | attr[1] = e1_port1; |
| 1898 | attr[2] = ts1; |
| 1899 | |
| 1900 | return abis_nm_sendmsg(bts, msg); |
| 1901 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1902 | |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 1903 | /* Chapter 8.7.1 */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1904 | int abis_nm_perform_test(struct gsm_bts *bts, uint8_t obj_class, |
| 1905 | uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, |
| 1906 | uint8_t test_nr, uint8_t auton_report, struct msgb *msg) |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 1907 | { |
| 1908 | struct abis_om_hdr *oh; |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 1909 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 1910 | DEBUGP(DNM, "PEFORM TEST %s\n", abis_nm_test_name(test_nr)); |
Harald Welte | b31c9df | 2010-03-06 11:38:05 +0100 | [diff] [blame] | 1911 | |
| 1912 | if (!msg) |
| 1913 | msg = nm_msgb_alloc(); |
| 1914 | |
| 1915 | msgb_tv_push(msg, NM_ATT_AUTON_REPORT, auton_report); |
| 1916 | msgb_tv_push(msg, NM_ATT_TEST_NO, test_nr); |
| 1917 | oh = (struct abis_om_hdr *) msgb_push(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1918 | fill_om_fom_hdr(oh, msgb_l3len(msg), NM_MT_PERF_TEST, |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 1919 | obj_class, bts_nr, trx_nr, ts_nr); |
Harald Welte | 0bf8e30 | 2009-08-08 00:02:36 +0200 | [diff] [blame] | 1920 | |
| 1921 | return abis_nm_sendmsg(bts, msg); |
| 1922 | } |
| 1923 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1924 | int abis_nm_event_reports(struct gsm_bts *bts, int on) |
| 1925 | { |
| 1926 | if (on == 0) |
| 1927 | return __simple_cmd(bts, NM_MT_STOP_EVENT_REP); |
| 1928 | else |
| 1929 | return __simple_cmd(bts, NM_MT_REST_EVENT_REP); |
| 1930 | } |
| 1931 | |
| 1932 | /* Siemens (or BS-11) specific commands */ |
| 1933 | |
| 1934 | int abis_nm_bs11_bsc_disconnect(struct gsm_bts *bts, int reconnect) |
| 1935 | { |
| 1936 | if (reconnect == 0) |
| 1937 | return __simple_cmd(bts, NM_MT_BS11_DISCONNECT); |
| 1938 | else |
| 1939 | return __simple_cmd(bts, NM_MT_BS11_RECONNECT); |
| 1940 | } |
| 1941 | |
| 1942 | int abis_nm_bs11_restart(struct gsm_bts *bts) |
| 1943 | { |
| 1944 | return __simple_cmd(bts, NM_MT_BS11_RESTART); |
| 1945 | } |
| 1946 | |
| 1947 | |
| 1948 | struct bs11_date_time { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1949 | uint16_t year; |
| 1950 | uint8_t month; |
| 1951 | uint8_t day; |
| 1952 | uint8_t hour; |
| 1953 | uint8_t min; |
| 1954 | uint8_t sec; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1955 | } __attribute__((packed)); |
| 1956 | |
| 1957 | |
| 1958 | void get_bs11_date_time(struct bs11_date_time *aet) |
| 1959 | { |
| 1960 | time_t t; |
| 1961 | struct tm *tm; |
| 1962 | |
| 1963 | t = time(NULL); |
| 1964 | tm = localtime(&t); |
| 1965 | aet->sec = tm->tm_sec; |
| 1966 | aet->min = tm->tm_min; |
| 1967 | aet->hour = tm->tm_hour; |
| 1968 | aet->day = tm->tm_mday; |
| 1969 | aet->month = tm->tm_mon; |
| 1970 | aet->year = htons(1900 + tm->tm_year); |
| 1971 | } |
| 1972 | |
| 1973 | int abis_nm_bs11_reset_resource(struct gsm_bts *bts) |
| 1974 | { |
| 1975 | return __simple_cmd(bts, NM_MT_BS11_RESET_RESOURCE); |
| 1976 | } |
| 1977 | |
| 1978 | int abis_nm_bs11_db_transmission(struct gsm_bts *bts, int begin) |
| 1979 | { |
| 1980 | if (begin) |
| 1981 | return __simple_cmd(bts, NM_MT_BS11_BEGIN_DB_TX); |
| 1982 | else |
| 1983 | return __simple_cmd(bts, NM_MT_BS11_END_DB_TX); |
| 1984 | } |
| 1985 | |
| 1986 | int abis_nm_bs11_create_object(struct gsm_bts *bts, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1987 | enum abis_bs11_objtype type, uint8_t idx, |
| 1988 | uint8_t attr_len, const uint8_t *attr) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1989 | { |
| 1990 | struct abis_om_hdr *oh; |
| 1991 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 1992 | uint8_t *cur; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1993 | |
| 1994 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 1995 | fill_om_fom_hdr(oh, attr_len, NM_MT_BS11_CREATE_OBJ, |
| 1996 | NM_OC_BS11, type, 0, idx); |
| 1997 | cur = msgb_put(msg, attr_len); |
| 1998 | memcpy(cur, attr, attr_len); |
| 1999 | |
| 2000 | return abis_nm_sendmsg(bts, msg); |
| 2001 | } |
| 2002 | |
| 2003 | int abis_nm_bs11_delete_object(struct gsm_bts *bts, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2004 | enum abis_bs11_objtype type, uint8_t idx) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2005 | { |
| 2006 | struct abis_om_hdr *oh; |
| 2007 | struct msgb *msg = nm_msgb_alloc(); |
| 2008 | |
| 2009 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2010 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ, |
| 2011 | NM_OC_BS11, type, 0, idx); |
| 2012 | |
| 2013 | return abis_nm_sendmsg(bts, msg); |
| 2014 | } |
| 2015 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2016 | int abis_nm_bs11_create_envaBTSE(struct gsm_bts *bts, uint8_t idx) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2017 | { |
| 2018 | struct abis_om_hdr *oh; |
| 2019 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2020 | uint8_t zero = 0x00; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2021 | |
| 2022 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2023 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_CREATE_OBJ, |
| 2024 | NM_OC_BS11_ENVABTSE, 0, idx, 0xff); |
| 2025 | msgb_tlv_put(msg, 0x99, 1, &zero); |
| 2026 | |
| 2027 | return abis_nm_sendmsg(bts, msg); |
| 2028 | } |
| 2029 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2030 | int abis_nm_bs11_create_bport(struct gsm_bts *bts, uint8_t idx) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2031 | { |
| 2032 | struct abis_om_hdr *oh; |
| 2033 | struct msgb *msg = nm_msgb_alloc(); |
| 2034 | |
| 2035 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2036 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_CREATE_OBJ, NM_OC_BS11_BPORT, |
Daniel Willmann | 5655afe | 2009-08-10 11:49:36 +0200 | [diff] [blame] | 2037 | idx, 0xff, 0xff); |
| 2038 | |
| 2039 | return abis_nm_sendmsg(bts, msg); |
| 2040 | } |
| 2041 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2042 | int abis_nm_bs11_delete_bport(struct gsm_bts *bts, uint8_t idx) |
Daniel Willmann | 5655afe | 2009-08-10 11:49:36 +0200 | [diff] [blame] | 2043 | { |
| 2044 | struct abis_om_hdr *oh; |
| 2045 | struct msgb *msg = nm_msgb_alloc(); |
| 2046 | |
| 2047 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2048 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_DELETE_OBJ, NM_OC_BS11_BPORT, |
| 2049 | idx, 0xff, 0xff); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2050 | |
| 2051 | return abis_nm_sendmsg(bts, msg); |
| 2052 | } |
| 2053 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2054 | static const uint8_t sm_attr[] = { NM_ATT_TEI, NM_ATT_ABIS_CHANNEL }; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2055 | int abis_nm_bs11_get_oml_tei_ts(struct gsm_bts *bts) |
| 2056 | { |
| 2057 | struct abis_om_hdr *oh; |
| 2058 | struct msgb *msg = nm_msgb_alloc(); |
| 2059 | |
| 2060 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2061 | fill_om_fom_hdr(oh, 2+sizeof(sm_attr), NM_MT_GET_ATTR, NM_OC_SITE_MANAGER, |
| 2062 | 0xff, 0xff, 0xff); |
| 2063 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(sm_attr), sm_attr); |
| 2064 | |
| 2065 | return abis_nm_sendmsg(bts, msg); |
| 2066 | } |
| 2067 | |
| 2068 | /* like abis_nm_conn_terr_traf + set_tei */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2069 | int abis_nm_bs11_conn_oml_tei(struct gsm_bts *bts, uint8_t e1_port, |
| 2070 | uint8_t e1_timeslot, uint8_t e1_subslot, |
| 2071 | uint8_t tei) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2072 | { |
| 2073 | struct abis_om_hdr *oh; |
| 2074 | struct abis_nm_channel *ch; |
| 2075 | struct msgb *msg = nm_msgb_alloc(); |
| 2076 | |
| 2077 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2078 | fill_om_fom_hdr(oh, sizeof(*ch)+2, NM_MT_BS11_SET_ATTR, |
| 2079 | NM_OC_SITE_MANAGER, 0xff, 0xff, 0xff); |
| 2080 | |
| 2081 | ch = (struct abis_nm_channel *) msgb_put(msg, sizeof(*ch)); |
| 2082 | fill_nm_channel(ch, e1_port, e1_timeslot, e1_subslot); |
| 2083 | msgb_tv_put(msg, NM_ATT_TEI, tei); |
| 2084 | |
| 2085 | return abis_nm_sendmsg(bts, msg); |
| 2086 | } |
| 2087 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2088 | int abis_nm_bs11_set_trx_power(struct gsm_bts_trx *trx, uint8_t level) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2089 | { |
| 2090 | struct abis_om_hdr *oh; |
| 2091 | struct msgb *msg = nm_msgb_alloc(); |
| 2092 | |
| 2093 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2094 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, |
| 2095 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 2096 | msgb_tlv_put(msg, NM_ATT_BS11_TXPWR, 1, &level); |
| 2097 | |
| 2098 | return abis_nm_sendmsg(trx->bts, msg); |
| 2099 | } |
| 2100 | |
| 2101 | int abis_nm_bs11_get_trx_power(struct gsm_bts_trx *trx) |
| 2102 | { |
| 2103 | struct abis_om_hdr *oh; |
| 2104 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2105 | uint8_t attr = NM_ATT_BS11_TXPWR; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2106 | |
| 2107 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2108 | fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR, |
| 2109 | NM_OC_BS11, BS11_OBJ_PA, 0x00, trx->nr); |
| 2110 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr); |
| 2111 | |
| 2112 | return abis_nm_sendmsg(trx->bts, msg); |
| 2113 | } |
| 2114 | |
| 2115 | int abis_nm_bs11_get_pll_mode(struct gsm_bts *bts) |
| 2116 | { |
| 2117 | struct abis_om_hdr *oh; |
| 2118 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2119 | uint8_t attr[] = { NM_ATT_BS11_PLL_MODE }; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2120 | |
| 2121 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2122 | fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR, |
| 2123 | NM_OC_BS11, BS11_OBJ_LI, 0x00, 0x00); |
| 2124 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr); |
| 2125 | |
| 2126 | return abis_nm_sendmsg(bts, msg); |
| 2127 | } |
| 2128 | |
| 2129 | int abis_nm_bs11_get_cclk(struct gsm_bts *bts) |
| 2130 | { |
| 2131 | struct abis_om_hdr *oh; |
| 2132 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2133 | uint8_t attr[] = { NM_ATT_BS11_CCLK_ACCURACY, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2134 | NM_ATT_BS11_CCLK_TYPE }; |
| 2135 | |
| 2136 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2137 | fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR, |
| 2138 | NM_OC_BS11, BS11_OBJ_CCLK, 0x00, 0x00); |
| 2139 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), attr); |
| 2140 | |
| 2141 | return abis_nm_sendmsg(bts, msg); |
| 2142 | |
| 2143 | } |
| 2144 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2145 | //static const uint8_t bs11_logon_c7[] = { 0x07, 0xd9, 0x01, 0x11, 0x0d, 0x10, 0x20 }; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2146 | |
| 2147 | int abis_nm_bs11_factory_logon(struct gsm_bts *bts, int on) |
| 2148 | { |
Daniel Willmann | cb8f250 | 2010-01-07 00:43:11 +0100 | [diff] [blame] | 2149 | return abis_nm_bs11_logon(bts, 0x02, "FACTORY", on); |
| 2150 | } |
| 2151 | |
Daniel Willmann | bf2ca57 | 2010-01-07 00:46:26 +0100 | [diff] [blame] | 2152 | int abis_nm_bs11_infield_logon(struct gsm_bts *bts, int on) |
| 2153 | { |
| 2154 | return abis_nm_bs11_logon(bts, 0x03, "FIELD ", on); |
| 2155 | } |
| 2156 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2157 | int abis_nm_bs11_logon(struct gsm_bts *bts, uint8_t level, const char *name, int on) |
Daniel Willmann | cb8f250 | 2010-01-07 00:43:11 +0100 | [diff] [blame] | 2158 | { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2159 | struct abis_om_hdr *oh; |
| 2160 | struct msgb *msg = nm_msgb_alloc(); |
| 2161 | struct bs11_date_time bdt; |
| 2162 | |
| 2163 | get_bs11_date_time(&bdt); |
| 2164 | |
| 2165 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2166 | if (on) { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2167 | uint8_t len = 3*2 + sizeof(bdt) |
Daniel Willmann | cb8f250 | 2010-01-07 00:43:11 +0100 | [diff] [blame] | 2168 | + 1 + strlen(name); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2169 | fill_om_fom_hdr(oh, len, NM_MT_BS11_LMT_LOGON, |
| 2170 | NM_OC_BS11_BTSE, 0xff, 0xff, 0xff); |
| 2171 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_LOGIN_TIME, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2172 | sizeof(bdt), (uint8_t *) &bdt); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2173 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_ACC_LEV, |
Daniel Willmann | cb8f250 | 2010-01-07 00:43:11 +0100 | [diff] [blame] | 2174 | 1, &level); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2175 | msgb_tlv_put(msg, NM_ATT_BS11_LMT_USER_NAME, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2176 | strlen(name), (uint8_t *)name); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2177 | } else { |
| 2178 | fill_om_fom_hdr(oh, 0, NM_MT_BS11_LMT_LOGOFF, |
| 2179 | NM_OC_BS11_BTSE, 0xff, 0xff, 0xff); |
| 2180 | } |
| 2181 | |
| 2182 | return abis_nm_sendmsg(bts, msg); |
| 2183 | } |
| 2184 | |
| 2185 | int abis_nm_bs11_set_trx1_pw(struct gsm_bts *bts, const char *password) |
| 2186 | { |
| 2187 | struct abis_om_hdr *oh; |
| 2188 | struct msgb *msg; |
| 2189 | |
| 2190 | if (strlen(password) != 10) |
| 2191 | return -EINVAL; |
| 2192 | |
| 2193 | msg = nm_msgb_alloc(); |
| 2194 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2195 | fill_om_fom_hdr(oh, 2+strlen(password), NM_MT_BS11_SET_ATTR, |
| 2196 | NM_OC_BS11, BS11_OBJ_TRX1, 0x00, 0x00); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2197 | msgb_tlv_put(msg, NM_ATT_BS11_PASSWORD, 10, (const uint8_t *)password); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2198 | |
| 2199 | return abis_nm_sendmsg(bts, msg); |
| 2200 | } |
| 2201 | |
| 2202 | /* change the BS-11 PLL Mode to either locked (E1 derived) or standalone */ |
| 2203 | int abis_nm_bs11_set_pll_locked(struct gsm_bts *bts, int locked) |
| 2204 | { |
| 2205 | struct abis_om_hdr *oh; |
| 2206 | struct msgb *msg; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2207 | uint8_t tlv_value; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2208 | |
| 2209 | msg = nm_msgb_alloc(); |
| 2210 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2211 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11, |
| 2212 | BS11_OBJ_LI, 0x00, 0x00); |
| 2213 | |
| 2214 | if (locked) |
| 2215 | tlv_value = BS11_LI_PLL_LOCKED; |
| 2216 | else |
| 2217 | tlv_value = BS11_LI_PLL_STANDALONE; |
| 2218 | |
| 2219 | msgb_tlv_put(msg, NM_ATT_BS11_PLL_MODE, 1, &tlv_value); |
| 2220 | |
| 2221 | return abis_nm_sendmsg(bts, msg); |
| 2222 | } |
| 2223 | |
Daniel Willmann | 10b07db | 2010-01-07 00:54:01 +0100 | [diff] [blame] | 2224 | /* Set the calibration value of the PLL (work value/set value) |
| 2225 | * It depends on the login which one is changed */ |
| 2226 | int abis_nm_bs11_set_pll(struct gsm_bts *bts, int value) |
| 2227 | { |
| 2228 | struct abis_om_hdr *oh; |
| 2229 | struct msgb *msg; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2230 | uint8_t tlv_value[2]; |
Daniel Willmann | 10b07db | 2010-01-07 00:54:01 +0100 | [diff] [blame] | 2231 | |
| 2232 | msg = nm_msgb_alloc(); |
| 2233 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2234 | fill_om_fom_hdr(oh, 3, NM_MT_BS11_SET_ATTR, NM_OC_BS11, |
| 2235 | BS11_OBJ_TRX1, 0x00, 0x00); |
| 2236 | |
| 2237 | tlv_value[0] = value>>8; |
| 2238 | tlv_value[1] = value&0xff; |
| 2239 | |
| 2240 | msgb_tlv_put(msg, NM_ATT_BS11_PLL, 2, tlv_value); |
| 2241 | |
| 2242 | return abis_nm_sendmsg(bts, msg); |
| 2243 | } |
| 2244 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2245 | int abis_nm_bs11_get_state(struct gsm_bts *bts) |
| 2246 | { |
| 2247 | return __simple_cmd(bts, NM_MT_BS11_GET_STATE); |
| 2248 | } |
| 2249 | |
| 2250 | /* BS11 SWL */ |
| 2251 | |
Harald Welte (local) | 8751ee9 | 2009-08-15 02:30:58 +0200 | [diff] [blame] | 2252 | void *tall_fle_ctx; |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 2253 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2254 | struct abis_nm_bs11_sw { |
| 2255 | struct gsm_bts *bts; |
| 2256 | char swl_fname[PATH_MAX]; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2257 | uint8_t win_size; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2258 | int forced; |
| 2259 | struct llist_head file_list; |
| 2260 | gsm_cbfn *user_cb; /* specified by the user */ |
| 2261 | }; |
| 2262 | static struct abis_nm_bs11_sw _g_bs11_sw, *g_bs11_sw = &_g_bs11_sw; |
| 2263 | |
| 2264 | struct file_list_entry { |
| 2265 | struct llist_head list; |
| 2266 | char fname[PATH_MAX]; |
| 2267 | }; |
| 2268 | |
| 2269 | struct file_list_entry *fl_dequeue(struct llist_head *queue) |
| 2270 | { |
| 2271 | struct llist_head *lh; |
| 2272 | |
| 2273 | if (llist_empty(queue)) |
| 2274 | return NULL; |
| 2275 | |
| 2276 | lh = queue->next; |
| 2277 | llist_del(lh); |
| 2278 | |
| 2279 | return llist_entry(lh, struct file_list_entry, list); |
| 2280 | } |
| 2281 | |
| 2282 | static int bs11_read_swl_file(struct abis_nm_bs11_sw *bs11_sw) |
| 2283 | { |
| 2284 | char linebuf[255]; |
| 2285 | struct llist_head *lh, *lh2; |
| 2286 | FILE *swl; |
| 2287 | int rc = 0; |
| 2288 | |
| 2289 | swl = fopen(bs11_sw->swl_fname, "r"); |
| 2290 | if (!swl) |
| 2291 | return -ENODEV; |
| 2292 | |
| 2293 | /* zero the stale file list, if any */ |
| 2294 | llist_for_each_safe(lh, lh2, &bs11_sw->file_list) { |
| 2295 | llist_del(lh); |
Harald Welte | a837977 | 2009-06-20 22:36:41 +0200 | [diff] [blame] | 2296 | talloc_free(lh); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | while (fgets(linebuf, sizeof(linebuf), swl)) { |
| 2300 | char file_id[12+1]; |
| 2301 | char file_version[80+1]; |
| 2302 | struct file_list_entry *fle; |
| 2303 | static char dir[PATH_MAX]; |
| 2304 | |
| 2305 | if (strlen(linebuf) < 4) |
| 2306 | continue; |
| 2307 | |
| 2308 | rc = sscanf(linebuf+4, "%12s:%80s\r\n", file_id, file_version); |
| 2309 | if (rc < 0) { |
| 2310 | perror("ERR parsing SWL file"); |
| 2311 | rc = -EINVAL; |
| 2312 | goto out; |
| 2313 | } |
| 2314 | if (rc < 2) |
| 2315 | continue; |
| 2316 | |
Harald Welte | 857e00d | 2009-06-26 20:25:23 +0200 | [diff] [blame] | 2317 | fle = talloc_zero(tall_fle_ctx, struct file_list_entry); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2318 | if (!fle) { |
| 2319 | rc = -ENOMEM; |
| 2320 | goto out; |
| 2321 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2322 | |
| 2323 | /* construct new filename */ |
Neels Hofmeyr | 5644c2b | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 2324 | osmo_strlcpy(dir, bs11_sw->swl_fname, sizeof(dir)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2325 | strncat(fle->fname, dirname(dir), sizeof(fle->fname) - 1); |
| 2326 | strcat(fle->fname, "/"); |
| 2327 | strncat(fle->fname, file_id, sizeof(fle->fname) - 1 -strlen(fle->fname)); |
| 2328 | |
| 2329 | llist_add_tail(&fle->list, &bs11_sw->file_list); |
| 2330 | } |
| 2331 | |
| 2332 | out: |
| 2333 | fclose(swl); |
| 2334 | return rc; |
| 2335 | } |
| 2336 | |
| 2337 | /* bs11 swload specific callback, passed to abis_nm core swload */ |
| 2338 | static int bs11_swload_cbfn(unsigned int hook, unsigned int event, |
| 2339 | struct msgb *msg, void *data, void *param) |
| 2340 | { |
| 2341 | struct abis_nm_bs11_sw *bs11_sw = data; |
| 2342 | struct file_list_entry *fle; |
| 2343 | int rc = 0; |
| 2344 | |
| 2345 | switch (event) { |
| 2346 | case NM_MT_LOAD_END_ACK: |
| 2347 | fle = fl_dequeue(&bs11_sw->file_list); |
| 2348 | if (fle) { |
| 2349 | /* start download the next file of our file list */ |
Holger Hans Peter Freyther | 2b4083a | 2010-05-12 23:51:46 +0800 | [diff] [blame] | 2350 | rc = abis_nm_software_load(bs11_sw->bts, 0xff, fle->fname, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2351 | bs11_sw->win_size, |
| 2352 | bs11_sw->forced, |
| 2353 | &bs11_swload_cbfn, bs11_sw); |
Harald Welte | b6328b9 | 2009-08-06 15:44:18 +0200 | [diff] [blame] | 2354 | talloc_free(fle); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2355 | } else { |
| 2356 | /* activate the SWL */ |
| 2357 | rc = abis_nm_software_activate(bs11_sw->bts, |
| 2358 | bs11_sw->swl_fname, |
| 2359 | bs11_swload_cbfn, |
| 2360 | bs11_sw); |
| 2361 | } |
| 2362 | break; |
| 2363 | case NM_MT_LOAD_SEG_ACK: |
| 2364 | case NM_MT_LOAD_END_NACK: |
| 2365 | case NM_MT_LOAD_INIT_ACK: |
| 2366 | case NM_MT_LOAD_INIT_NACK: |
| 2367 | case NM_MT_ACTIVATE_SW_NACK: |
| 2368 | case NM_MT_ACTIVATE_SW_ACK: |
| 2369 | default: |
| 2370 | /* fallthrough to the user callback */ |
| 2371 | if (bs11_sw->user_cb) |
| 2372 | rc = bs11_sw->user_cb(hook, event, msg, NULL, NULL); |
| 2373 | break; |
| 2374 | } |
| 2375 | |
| 2376 | return rc; |
| 2377 | } |
| 2378 | |
| 2379 | /* Siemens provides a SWL file that is a mere listing of all the other |
| 2380 | * files that are part of a software release. We need to upload first |
| 2381 | * the list file, and then each file that is listed in the list file */ |
| 2382 | int abis_nm_bs11_load_swl(struct gsm_bts *bts, const char *fname, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2383 | uint8_t win_size, int forced, gsm_cbfn *cbfn) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2384 | { |
| 2385 | struct abis_nm_bs11_sw *bs11_sw = g_bs11_sw; |
| 2386 | struct file_list_entry *fle; |
| 2387 | int rc = 0; |
| 2388 | |
| 2389 | INIT_LLIST_HEAD(&bs11_sw->file_list); |
| 2390 | bs11_sw->bts = bts; |
| 2391 | bs11_sw->win_size = win_size; |
| 2392 | bs11_sw->user_cb = cbfn; |
| 2393 | bs11_sw->forced = forced; |
| 2394 | |
Neels Hofmeyr | 5644c2b | 2017-01-13 03:12:08 +0100 | [diff] [blame] | 2395 | osmo_strlcpy(bs11_sw->swl_fname, fname, sizeof(bs11_sw->swl_fname)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2396 | rc = bs11_read_swl_file(bs11_sw); |
| 2397 | if (rc < 0) |
| 2398 | return rc; |
| 2399 | |
| 2400 | /* dequeue next item in file list */ |
| 2401 | fle = fl_dequeue(&bs11_sw->file_list); |
| 2402 | if (!fle) |
| 2403 | return -EINVAL; |
| 2404 | |
| 2405 | /* start download the next file of our file list */ |
Holger Hans Peter Freyther | 2b4083a | 2010-05-12 23:51:46 +0800 | [diff] [blame] | 2406 | rc = abis_nm_software_load(bts, 0xff, fle->fname, win_size, forced, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2407 | bs11_swload_cbfn, bs11_sw); |
Harald Welte | b6328b9 | 2009-08-06 15:44:18 +0200 | [diff] [blame] | 2408 | talloc_free(fle); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2409 | return rc; |
| 2410 | } |
| 2411 | |
| 2412 | #if 0 |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2413 | static uint8_t req_attr_btse[] = { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2414 | NM_ATT_ADM_STATE, NM_ATT_BS11_LMT_LOGON_SESSION, |
| 2415 | NM_ATT_BS11_LMT_LOGIN_TIME, NM_ATT_BS11_LMT_USER_ACC_LEV, |
| 2416 | NM_ATT_BS11_LMT_USER_NAME, |
| 2417 | |
| 2418 | 0xaf, NM_ATT_BS11_RX_OFFSET, NM_ATT_BS11_VENDOR_NAME, |
| 2419 | |
| 2420 | NM_ATT_BS11_SW_LOAD_INTENDED, NM_ATT_BS11_SW_LOAD_SAFETY, |
| 2421 | |
| 2422 | NM_ATT_BS11_SW_LOAD_STORED }; |
| 2423 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2424 | static uint8_t req_attr_btsm[] = { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2425 | NM_ATT_ABIS_CHANNEL, NM_ATT_TEI, NM_ATT_BS11_ABIS_EXT_TIME, |
| 2426 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xce, NM_ATT_FILE_ID, |
| 2427 | NM_ATT_FILE_VERSION, NM_ATT_OPER_STATE, 0xe8, NM_ATT_BS11_ALL_TEST_CATG, |
| 2428 | NM_ATT_SW_DESCR, NM_ATT_GET_ARI }; |
| 2429 | #endif |
| 2430 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2431 | static uint8_t req_attr[] = { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2432 | NM_ATT_ADM_STATE, NM_ATT_AVAIL_STATUS, 0xa8, NM_ATT_OPER_STATE, |
| 2433 | 0xd5, 0xa1, NM_ATT_BS11_ESN_FW_CODE_NO, NM_ATT_BS11_ESN_HW_CODE_NO, |
| 2434 | 0x42, NM_ATT_BS11_ESN_PCB_SERIAL, NM_ATT_BS11_PLL }; |
| 2435 | |
| 2436 | int abis_nm_bs11_get_serno(struct gsm_bts *bts) |
| 2437 | { |
| 2438 | struct abis_om_hdr *oh; |
| 2439 | struct msgb *msg = nm_msgb_alloc(); |
| 2440 | |
| 2441 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2442 | /* SiemensHW CCTRL object */ |
| 2443 | fill_om_fom_hdr(oh, 2+sizeof(req_attr), NM_MT_GET_ATTR, NM_OC_BS11, |
| 2444 | 0x03, 0x00, 0x00); |
| 2445 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(req_attr), req_attr); |
| 2446 | |
| 2447 | return abis_nm_sendmsg(bts, msg); |
| 2448 | } |
| 2449 | |
| 2450 | int abis_nm_bs11_set_ext_time(struct gsm_bts *bts) |
| 2451 | { |
| 2452 | struct abis_om_hdr *oh; |
| 2453 | struct msgb *msg = nm_msgb_alloc(); |
| 2454 | struct bs11_date_time aet; |
| 2455 | |
| 2456 | get_bs11_date_time(&aet); |
| 2457 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2458 | /* SiemensHW CCTRL object */ |
| 2459 | fill_om_fom_hdr(oh, 2+sizeof(aet), NM_MT_BS11_SET_ATTR, NM_OC_SITE_MANAGER, |
| 2460 | 0xff, 0xff, 0xff); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2461 | msgb_tlv_put(msg, NM_ATT_BS11_ABIS_EXT_TIME, sizeof(aet), (uint8_t *) &aet); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2462 | |
| 2463 | return abis_nm_sendmsg(bts, msg); |
| 2464 | } |
| 2465 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2466 | int abis_nm_bs11_get_bport_line_cfg(struct gsm_bts *bts, uint8_t bport) |
Harald Welte | 30534c5 | 2010-12-14 12:52:16 +0100 | [diff] [blame] | 2467 | { |
| 2468 | struct abis_om_hdr *oh; |
| 2469 | struct msgb *msg = nm_msgb_alloc(); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2470 | uint8_t attr = NM_ATT_BS11_LINE_CFG; |
Harald Welte | 30534c5 | 2010-12-14 12:52:16 +0100 | [diff] [blame] | 2471 | |
| 2472 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2473 | fill_om_fom_hdr(oh, 2+sizeof(attr), NM_MT_GET_ATTR, |
| 2474 | NM_OC_BS11_BPORT, bport, 0xff, 0x02); |
| 2475 | msgb_tlv_put(msg, NM_ATT_LIST_REQ_ATTR, sizeof(attr), &attr); |
| 2476 | |
| 2477 | return abis_nm_sendmsg(bts, msg); |
| 2478 | } |
| 2479 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2480 | int abis_nm_bs11_set_bport_line_cfg(struct gsm_bts *bts, uint8_t bport, enum abis_bs11_line_cfg line_cfg) |
Daniel Willmann | 5655afe | 2009-08-10 11:49:36 +0200 | [diff] [blame] | 2481 | { |
| 2482 | struct abis_om_hdr *oh; |
| 2483 | struct msgb *msg = nm_msgb_alloc(); |
| 2484 | struct bs11_date_time aet; |
| 2485 | |
| 2486 | get_bs11_date_time(&aet); |
| 2487 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2488 | fill_om_fom_hdr(oh, 2, NM_MT_BS11_SET_ATTR, NM_OC_BS11_BPORT, |
| 2489 | bport, 0xff, 0x02); |
| 2490 | msgb_tv_put(msg, NM_ATT_BS11_LINE_CFG, line_cfg); |
| 2491 | |
| 2492 | return abis_nm_sendmsg(bts, msg); |
| 2493 | } |
| 2494 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2495 | /* ip.access nanoBTS specific commands */ |
| 2496 | static const char ipaccess_magic[] = "com.ipaccess"; |
| 2497 | |
| 2498 | |
| 2499 | static int abis_nm_rx_ipacc(struct msgb *msg) |
| 2500 | { |
Holger Hans Peter Freyther | d3b6f94 | 2010-06-21 10:22:26 +0800 | [diff] [blame] | 2501 | struct in_addr addr; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2502 | struct abis_om_hdr *oh = msgb_l2(msg); |
| 2503 | struct abis_om_fom_hdr *foh; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2504 | uint8_t idstrlen = oh->data[0]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2505 | struct tlv_parsed tp; |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 2506 | struct ipacc_ack_signal_data signal; |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 2507 | struct e1inp_sign_link *sign_link = msg->dst; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2508 | |
| 2509 | if (strncmp((char *)&oh->data[1], ipaccess_magic, idstrlen)) { |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2510 | LOGP(DNM, LOGL_ERROR, "id string is not com.ipaccess !?!\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2511 | return -EINVAL; |
| 2512 | } |
| 2513 | |
| 2514 | foh = (struct abis_om_fom_hdr *) (oh->data + 1 + idstrlen); |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 2515 | abis_nm_tlv_parse(&tp, sign_link->trx->bts, foh->data, oh->length-sizeof(*foh)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2516 | |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 2517 | abis_nm_debugp_foh(DNM, foh); |
Harald Welte | fd579d5 | 2009-10-19 21:46:54 +0200 | [diff] [blame] | 2518 | |
Harald Welte | 5aeedd4 | 2009-10-19 22:11:11 +0200 | [diff] [blame] | 2519 | DEBUGPC(DNM, "IPACCESS(0x%02x): ", foh->msg_type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2520 | |
| 2521 | switch (foh->msg_type) { |
| 2522 | case NM_MT_IPACC_RSL_CONNECT_ACK: |
| 2523 | DEBUGPC(DNM, "RSL CONNECT ACK "); |
Holger Hans Peter Freyther | d3b6f94 | 2010-06-21 10:22:26 +0800 | [diff] [blame] | 2524 | if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP)) { |
| 2525 | memcpy(&addr, |
| 2526 | TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP), sizeof(addr)); |
| 2527 | |
| 2528 | DEBUGPC(DNM, "IP=%s ", inet_ntoa(addr)); |
| 2529 | } |
Harald Welte | 4206d98 | 2009-07-12 09:33:54 +0200 | [diff] [blame] | 2530 | if (TLVP_PRESENT(&tp, NM_ATT_IPACC_DST_IP_PORT)) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2531 | DEBUGPC(DNM, "PORT=%u ", |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2532 | ntohs(*((uint16_t *) |
Harald Welte | 4206d98 | 2009-07-12 09:33:54 +0200 | [diff] [blame] | 2533 | TLVP_VAL(&tp, NM_ATT_IPACC_DST_IP_PORT)))); |
Harald Welte | 0eccfd0 | 2009-10-19 22:49:33 +0200 | [diff] [blame] | 2534 | if (TLVP_PRESENT(&tp, NM_ATT_IPACC_STREAM_ID)) |
| 2535 | DEBUGPC(DNM, "STREAM=0x%02x ", |
| 2536 | *TLVP_VAL(&tp, NM_ATT_IPACC_STREAM_ID)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2537 | DEBUGPC(DNM, "\n"); |
| 2538 | break; |
| 2539 | case NM_MT_IPACC_RSL_CONNECT_NACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2540 | LOGP(DNM, LOGL_ERROR, "RSL CONNECT NACK "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2541 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
Alexander Chemeris | f3f3d30 | 2013-10-06 23:35:39 +0200 | [diff] [blame] | 2542 | LOGPC(DNM, LOGL_ERROR, " CAUSE=%s\n", |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 2543 | abis_nm_nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2544 | else |
Alexander Chemeris | f3f3d30 | 2013-10-06 23:35:39 +0200 | [diff] [blame] | 2545 | LOGPC(DNM, LOGL_ERROR, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2546 | break; |
| 2547 | case NM_MT_IPACC_SET_NVATTR_ACK: |
| 2548 | DEBUGPC(DNM, "SET NVATTR ACK\n"); |
| 2549 | /* FIXME: decode and show the actual attributes */ |
| 2550 | break; |
| 2551 | case NM_MT_IPACC_SET_NVATTR_NACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2552 | LOGP(DNM, LOGL_ERROR, "SET NVATTR NACK "); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2553 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 2554 | LOGPC(DNM, LOGL_ERROR, " CAUSE=%s\n", |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 2555 | abis_nm_nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2556 | else |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2557 | LOGPC(DNM, LOGL_ERROR, "\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2558 | break; |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 2559 | case NM_MT_IPACC_GET_NVATTR_ACK: |
| 2560 | DEBUGPC(DNM, "GET NVATTR ACK\n"); |
| 2561 | /* FIXME: decode and show the actual attributes */ |
| 2562 | break; |
| 2563 | case NM_MT_IPACC_GET_NVATTR_NACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2564 | LOGPC(DNM, LOGL_ERROR, "GET NVATTR NACK "); |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 2565 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 2566 | LOGPC(DNM, LOGL_ERROR, " CAUSE=%s\n", |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 2567 | abis_nm_nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 2568 | else |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2569 | LOGPC(DNM, LOGL_ERROR, "\n"); |
Harald Welte | 21460f0 | 2009-07-03 11:26:45 +0200 | [diff] [blame] | 2570 | break; |
Harald Welte | c76a217 | 2009-10-08 20:15:24 +0200 | [diff] [blame] | 2571 | case NM_MT_IPACC_SET_ATTR_ACK: |
| 2572 | DEBUGPC(DNM, "SET ATTR ACK\n"); |
| 2573 | break; |
| 2574 | case NM_MT_IPACC_SET_ATTR_NACK: |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2575 | LOGPC(DNM, LOGL_ERROR, "SET ATTR NACK "); |
Harald Welte | c76a217 | 2009-10-08 20:15:24 +0200 | [diff] [blame] | 2576 | if (TLVP_PRESENT(&tp, NM_ATT_NACK_CAUSES)) |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 2577 | LOGPC(DNM, LOGL_ERROR, " CAUSE=%s\n", |
Harald Welte | c61a90e | 2011-05-22 22:45:37 +0200 | [diff] [blame] | 2578 | abis_nm_nack_cause_name(*TLVP_VAL(&tp, NM_ATT_NACK_CAUSES))); |
Harald Welte | c76a217 | 2009-10-08 20:15:24 +0200 | [diff] [blame] | 2579 | else |
Harald Welte | de4477a | 2009-12-24 12:20:20 +0100 | [diff] [blame] | 2580 | LOGPC(DNM, LOGL_ERROR, "\n"); |
Harald Welte | c76a217 | 2009-10-08 20:15:24 +0200 | [diff] [blame] | 2581 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2582 | default: |
| 2583 | DEBUGPC(DNM, "unknown\n"); |
| 2584 | break; |
| 2585 | } |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 2586 | |
| 2587 | /* signal handling */ |
| 2588 | switch (foh->msg_type) { |
| 2589 | case NM_MT_IPACC_RSL_CONNECT_NACK: |
| 2590 | case NM_MT_IPACC_SET_NVATTR_NACK: |
| 2591 | case NM_MT_IPACC_GET_NVATTR_NACK: |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 2592 | signal.trx = gsm_bts_trx_by_nr(sign_link->trx->bts, foh->obj_inst.trx_nr); |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 2593 | signal.msg_type = foh->msg_type; |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 2594 | osmo_signal_dispatch(SS_NM, S_NM_IPACC_NACK, &signal); |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 2595 | break; |
Holger Hans Peter Freyther | 257b8db | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 2596 | case NM_MT_IPACC_SET_NVATTR_ACK: |
Pablo Neira Ayuso | 88c9bba | 2011-08-17 22:43:54 +0200 | [diff] [blame] | 2597 | signal.trx = gsm_bts_trx_by_nr(sign_link->trx->bts, foh->obj_inst.trx_nr); |
Holger Hans Peter Freyther | 0fc5ab4 | 2009-12-30 08:38:43 +0100 | [diff] [blame] | 2598 | signal.msg_type = foh->msg_type; |
Pablo Neira Ayuso | ef717c6 | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 2599 | osmo_signal_dispatch(SS_NM, S_NM_IPACC_ACK, &signal); |
Holger Hans Peter Freyther | 257b8db | 2009-12-29 11:26:38 +0100 | [diff] [blame] | 2600 | break; |
Holger Hans Peter Freyther | 72baef3 | 2009-07-07 12:40:07 +0200 | [diff] [blame] | 2601 | default: |
| 2602 | break; |
| 2603 | } |
| 2604 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2605 | return 0; |
| 2606 | } |
| 2607 | |
| 2608 | /* send an ip-access manufacturer specific message */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2609 | int abis_nm_ipaccess_msg(struct gsm_bts *bts, uint8_t msg_type, |
| 2610 | uint8_t obj_class, uint8_t bts_nr, |
| 2611 | uint8_t trx_nr, uint8_t ts_nr, |
| 2612 | uint8_t *attr, int attr_len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2613 | { |
| 2614 | struct msgb *msg = nm_msgb_alloc(); |
| 2615 | struct abis_om_hdr *oh; |
| 2616 | struct abis_om_fom_hdr *foh; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2617 | uint8_t *data; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2618 | |
| 2619 | /* construct the 12.21 OM header, observe the erroneous length */ |
| 2620 | oh = (struct abis_om_hdr *) msgb_put(msg, sizeof(*oh)); |
| 2621 | fill_om_hdr(oh, sizeof(*foh) + attr_len); |
| 2622 | oh->mdisc = ABIS_OM_MDISC_MANUF; |
| 2623 | |
| 2624 | /* add the ip.access magic */ |
| 2625 | data = msgb_put(msg, sizeof(ipaccess_magic)+1); |
| 2626 | *data++ = sizeof(ipaccess_magic); |
| 2627 | memcpy(data, ipaccess_magic, sizeof(ipaccess_magic)); |
| 2628 | |
| 2629 | /* fill the 12.21 FOM header */ |
| 2630 | foh = (struct abis_om_fom_hdr *) msgb_put(msg, sizeof(*foh)); |
| 2631 | foh->msg_type = msg_type; |
| 2632 | foh->obj_class = obj_class; |
| 2633 | foh->obj_inst.bts_nr = bts_nr; |
| 2634 | foh->obj_inst.trx_nr = trx_nr; |
| 2635 | foh->obj_inst.ts_nr = ts_nr; |
| 2636 | |
| 2637 | if (attr && attr_len) { |
| 2638 | data = msgb_put(msg, attr_len); |
| 2639 | memcpy(data, attr, attr_len); |
| 2640 | } |
| 2641 | |
| 2642 | return abis_nm_sendmsg(bts, msg); |
| 2643 | } |
| 2644 | |
| 2645 | /* set some attributes in NVRAM */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2646 | int abis_nm_ipaccess_set_nvattr(struct gsm_bts_trx *trx, uint8_t *attr, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2647 | int attr_len) |
| 2648 | { |
Harald Welte | f12c105 | 2010-01-07 20:39:42 +0100 | [diff] [blame] | 2649 | return abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_SET_NVATTR, |
| 2650 | NM_OC_BASEB_TRANSC, 0, trx->nr, 0xff, attr, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2651 | attr_len); |
| 2652 | } |
| 2653 | |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 2654 | int abis_nm_ipaccess_rsl_connect(struct gsm_bts_trx *trx, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2655 | uint32_t ip, uint16_t port, uint8_t stream) |
Harald Welte | 5aeedd4 | 2009-10-19 22:11:11 +0200 | [diff] [blame] | 2656 | { |
| 2657 | struct in_addr ia; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2658 | uint8_t attr[] = { NM_ATT_IPACC_STREAM_ID, 0, |
Harald Welte | 5aeedd4 | 2009-10-19 22:11:11 +0200 | [diff] [blame] | 2659 | NM_ATT_IPACC_DST_IP_PORT, 0, 0, |
| 2660 | NM_ATT_IPACC_DST_IP, 0, 0, 0, 0 }; |
| 2661 | |
| 2662 | int attr_len = sizeof(attr); |
| 2663 | |
| 2664 | ia.s_addr = htonl(ip); |
| 2665 | attr[1] = stream; |
| 2666 | attr[3] = port >> 8; |
| 2667 | attr[4] = port & 0xff; |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2668 | *(uint32_t *)(attr+6) = ia.s_addr; |
Harald Welte | 5aeedd4 | 2009-10-19 22:11:11 +0200 | [diff] [blame] | 2669 | |
| 2670 | /* if ip == 0, we use the default IP */ |
| 2671 | if (ip == 0) |
| 2672 | attr_len -= 5; |
| 2673 | |
| 2674 | DEBUGP(DNM, "ip.access RSL CONNECT IP=%s PORT=%u STREAM=0x%02x\n", |
Harald Welte | 6947c88 | 2009-10-19 22:50:30 +0200 | [diff] [blame] | 2675 | inet_ntoa(ia), port, stream); |
Harald Welte | 5aeedd4 | 2009-10-19 22:11:11 +0200 | [diff] [blame] | 2676 | |
| 2677 | return abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT, |
| 2678 | NM_OC_BASEB_TRANSC, trx->bts->bts_nr, |
| 2679 | trx->nr, 0xff, attr, attr_len); |
| 2680 | } |
| 2681 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2682 | /* restart / reboot an ip.access nanoBTS */ |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 2683 | int abis_nm_ipaccess_restart(struct gsm_bts_trx *trx) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2684 | { |
Holger Hans Peter Freyther | 3778384 | 2010-05-12 23:34:51 +0800 | [diff] [blame] | 2685 | struct abis_om_hdr *oh; |
| 2686 | struct msgb *msg = nm_msgb_alloc(); |
| 2687 | |
| 2688 | oh = (struct abis_om_hdr *) msgb_put(msg, ABIS_OM_FOM_HDR_SIZE); |
| 2689 | fill_om_fom_hdr(oh, 0, NM_MT_IPACC_RESTART, NM_OC_BASEB_TRANSC, |
| 2690 | trx->bts->nr, trx->nr, 0xff); |
| 2691 | |
Holger Hans Peter Freyther | c26d117 | 2016-03-16 14:27:29 +0100 | [diff] [blame] | 2692 | return abis_nm_sendmsg_direct(trx->bts, msg); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 2693 | } |
Harald Welte | 0dfc623 | 2009-10-24 10:20:41 +0200 | [diff] [blame] | 2694 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2695 | int abis_nm_ipaccess_set_attr(struct gsm_bts *bts, uint8_t obj_class, |
| 2696 | uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, |
| 2697 | uint8_t *attr, uint8_t attr_len) |
Harald Welte | 0dfc623 | 2009-10-24 10:20:41 +0200 | [diff] [blame] | 2698 | { |
| 2699 | return abis_nm_ipaccess_msg(bts, NM_MT_IPACC_SET_ATTR, |
| 2700 | obj_class, bts_nr, trx_nr, ts_nr, |
| 2701 | attr, attr_len); |
| 2702 | } |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2703 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2704 | void abis_nm_ipaccess_cgi(uint8_t *buf, struct gsm_bts *bts) |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 2705 | { |
| 2706 | /* we simply reuse the GSM48 function and overwrite the RAC |
| 2707 | * with the Cell ID */ |
| 2708 | gsm48_ra_id_by_bts(buf, bts); |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2709 | *((uint16_t *)(buf + 5)) = htons(bts->cell_identity); |
Harald Welte | 3055e33 | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 2710 | } |
| 2711 | |
Holger Hans Peter Freyther | 1c8b480 | 2009-11-11 11:54:24 +0100 | [diff] [blame] | 2712 | void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked) |
| 2713 | { |
| 2714 | int new_state = locked ? NM_STATE_LOCKED : NM_STATE_UNLOCKED; |
| 2715 | |
Harald Welte | 69f6f81 | 2011-05-30 12:07:53 +0200 | [diff] [blame] | 2716 | trx->mo.nm_state.administrative = new_state; |
Holger Hans Peter Freyther | 1c8b480 | 2009-11-11 11:54:24 +0100 | [diff] [blame] | 2717 | if (!trx->bts || !trx->bts->oml_link) |
| 2718 | return; |
| 2719 | |
| 2720 | abis_nm_chg_adm_state(trx->bts, NM_OC_RADIO_CARRIER, |
| 2721 | trx->bts->bts_nr, trx->nr, 0xff, |
| 2722 | new_state); |
| 2723 | } |
| 2724 | |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 2725 | static const struct value_string ipacc_testres_names[] = { |
| 2726 | { NM_IPACC_TESTRES_SUCCESS, "SUCCESS" }, |
| 2727 | { NM_IPACC_TESTRES_TIMEOUT, "TIMEOUT" }, |
| 2728 | { NM_IPACC_TESTRES_NO_CHANS, "NO CHANNELS" }, |
| 2729 | { NM_IPACC_TESTRES_PARTIAL, "PARTIAL" }, |
| 2730 | { NM_IPACC_TESTRES_STOPPED, "STOPPED" }, |
| 2731 | { 0, NULL } |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2732 | }; |
| 2733 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2734 | const char *ipacc_testres_name(uint8_t res) |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2735 | { |
Harald Welte | 453141f | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 2736 | return get_value_string(ipacc_testres_names, res); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2737 | } |
| 2738 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2739 | void ipac_parse_cgi(struct cell_global_id *cid, const uint8_t *buf) |
Harald Welte | bfc2109 | 2009-11-13 11:56:05 +0100 | [diff] [blame] | 2740 | { |
| 2741 | cid->mcc = (buf[0] & 0xf) * 100; |
| 2742 | cid->mcc += (buf[0] >> 4) * 10; |
| 2743 | cid->mcc += (buf[1] & 0xf) * 1; |
| 2744 | |
| 2745 | if (buf[1] >> 4 == 0xf) { |
| 2746 | cid->mnc = (buf[2] & 0xf) * 10; |
| 2747 | cid->mnc += (buf[2] >> 4) * 1; |
| 2748 | } else { |
| 2749 | cid->mnc = (buf[2] & 0xf) * 100; |
| 2750 | cid->mnc += (buf[2] >> 4) * 10; |
| 2751 | cid->mnc += (buf[1] >> 4) * 1; |
| 2752 | } |
| 2753 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2754 | cid->lac = ntohs(*((uint16_t *)&buf[3])); |
| 2755 | cid->ci = ntohs(*((uint16_t *)&buf[5])); |
Harald Welte | bfc2109 | 2009-11-13 11:56:05 +0100 | [diff] [blame] | 2756 | } |
| 2757 | |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2758 | /* parse BCCH information IEI from wire format to struct ipac_bcch_info */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2759 | int ipac_parse_bcch_info(struct ipac_bcch_info *binf, uint8_t *buf) |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2760 | { |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2761 | uint8_t *cur = buf; |
Holger Hans Peter Freyther | 1a9f3ee | 2012-09-11 11:55:03 +0200 | [diff] [blame] | 2762 | uint16_t len __attribute__((unused)); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2763 | |
Harald Welte | b784df8 | 2010-07-22 18:14:36 +0200 | [diff] [blame] | 2764 | memset(binf, 0, sizeof(*binf)); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2765 | |
| 2766 | if (cur[0] != NM_IPAC_EIE_BCCH_INFO) |
| 2767 | return -EINVAL; |
| 2768 | cur++; |
| 2769 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2770 | len = ntohs(*(uint16_t *)cur); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2771 | cur += 2; |
| 2772 | |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2773 | binf->info_type = ntohs(*(uint16_t *)cur); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2774 | cur += 2; |
| 2775 | |
| 2776 | if (binf->info_type & IPAC_BINF_FREQ_ERR_QUAL) |
| 2777 | binf->freq_qual = *cur >> 2; |
| 2778 | |
Harald Welte | b784df8 | 2010-07-22 18:14:36 +0200 | [diff] [blame] | 2779 | binf->arfcn = (*cur++ & 3) << 8; |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2780 | binf->arfcn |= *cur++; |
| 2781 | |
| 2782 | if (binf->info_type & IPAC_BINF_RXLEV) |
| 2783 | binf->rx_lev = *cur & 0x3f; |
| 2784 | cur++; |
| 2785 | |
| 2786 | if (binf->info_type & IPAC_BINF_RXQUAL) |
| 2787 | binf->rx_qual = *cur & 0x7; |
| 2788 | cur++; |
| 2789 | |
| 2790 | if (binf->info_type & IPAC_BINF_FREQ_ERR_QUAL) |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2791 | binf->freq_err = ntohs(*(uint16_t *)cur); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2792 | cur += 2; |
| 2793 | |
| 2794 | if (binf->info_type & IPAC_BINF_FRAME_OFFSET) |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2795 | binf->frame_offset = ntohs(*(uint16_t *)cur); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2796 | cur += 2; |
| 2797 | |
| 2798 | if (binf->info_type & IPAC_BINF_FRAME_NR_OFFSET) |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 2799 | binf->frame_nr_offset = ntohl(*(uint32_t *)cur); |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2800 | cur += 4; |
| 2801 | |
Harald Welte | 22cb81f | 2010-07-30 22:34:42 +0200 | [diff] [blame] | 2802 | #if 0 |
| 2803 | /* Somehow this is not set correctly */ |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2804 | if (binf->info_type & IPAC_BINF_BSIC) |
Harald Welte | 22cb81f | 2010-07-30 22:34:42 +0200 | [diff] [blame] | 2805 | #endif |
Harald Welte | 161b4be | 2009-11-13 14:41:52 +0100 | [diff] [blame] | 2806 | binf->bsic = *cur & 0x3f; |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2807 | cur++; |
| 2808 | |
Harald Welte | bfc2109 | 2009-11-13 11:56:05 +0100 | [diff] [blame] | 2809 | ipac_parse_cgi(&binf->cgi, cur); |
| 2810 | cur += 7; |
Harald Welte | beeae41 | 2009-11-12 14:48:42 +0100 | [diff] [blame] | 2811 | |
| 2812 | if (binf->info_type & IPAC_BINF_NEIGH_BA_SI2) { |
| 2813 | memcpy(binf->ba_list_si2, cur, sizeof(binf->ba_list_si2)); |
| 2814 | cur += sizeof(binf->ba_list_si2); |
| 2815 | } |
| 2816 | |
| 2817 | if (binf->info_type & IPAC_BINF_NEIGH_BA_SI2bis) { |
| 2818 | memcpy(binf->ba_list_si2bis, cur, |
| 2819 | sizeof(binf->ba_list_si2bis)); |
| 2820 | cur += sizeof(binf->ba_list_si2bis); |
| 2821 | } |
| 2822 | |
| 2823 | if (binf->info_type & IPAC_BINF_NEIGH_BA_SI2ter) { |
| 2824 | memcpy(binf->ba_list_si2ter, cur, |
| 2825 | sizeof(binf->ba_list_si2ter)); |
| 2826 | cur += sizeof(binf->ba_list_si2ter); |
| 2827 | } |
| 2828 | |
| 2829 | return 0; |
| 2830 | } |
Holger Hans Peter Freyther | 2a6bffe | 2010-11-15 20:50:42 +0100 | [diff] [blame] | 2831 | |
| 2832 | void abis_nm_clear_queue(struct gsm_bts *bts) |
| 2833 | { |
| 2834 | struct msgb *msg; |
| 2835 | |
| 2836 | while (!llist_empty(&bts->abis_queue)) { |
| 2837 | msg = msgb_dequeue(&bts->abis_queue); |
| 2838 | msgb_free(msg); |
| 2839 | } |
| 2840 | |
| 2841 | bts->abis_nm_pend = 0; |
| 2842 | } |