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