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