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