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