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