Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 1 | /* OpenBSC Debugging/Logging support code */ |
| 2 | |
| 3 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 4 | * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdarg.h> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <string.h> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 26 | #include <strings.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 27 | #include <time.h> |
Harald Welte (local) | b79bdd9 | 2009-12-26 19:45:22 +0100 | [diff] [blame] | 28 | #include <errno.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 29 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 30 | #include <osmocom/core/talloc.h> |
| 31 | #include <osmocom/core/utils.h> |
| 32 | #include <osmocom/core/logging.h> |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 33 | #include <openbsc/gsm_data.h> |
| 34 | #include <openbsc/gsm_subscriber.h> |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 35 | #include <openbsc/debug.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 37 | /* default categories */ |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 38 | static const struct log_info_cat default_categories[] = { |
| 39 | [DRLL] = { |
| 40 | .name = "DRLL", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 41 | .description = "A-bis Radio Link Layer (RLL)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 42 | .color = "\033[1;31m", |
| 43 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 44 | }, |
| 45 | [DCC] = { |
| 46 | .name = "DCC", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 47 | .description = "Layer3 Call Control (CC)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 48 | .color = "\033[1;32m", |
| 49 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 50 | }, |
| 51 | [DMM] = { |
| 52 | .name = "DMM", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 53 | .description = "Layer3 Mobility Management (MM)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 54 | .color = "\033[1;33m", |
| 55 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 56 | }, |
| 57 | [DRR] = { |
| 58 | .name = "DRR", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 59 | .description = "Layer3 Radio Resource (RR)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 60 | .color = "\033[1;34m", |
| 61 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 62 | }, |
| 63 | [DRSL] = { |
| 64 | .name = "DRSL", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 65 | .description = "A-bis Radio Siganlling Link (RSL)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 66 | .color = "\033[1;35m", |
| 67 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 68 | }, |
| 69 | [DNM] = { |
| 70 | .name = "DNM", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 71 | .description = "A-bis Network Management / O&M (NM/OML)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 72 | .color = "\033[1;36m", |
| 73 | .enabled = 1, .loglevel = LOGL_INFO, |
| 74 | }, |
| 75 | [DMNCC] = { |
| 76 | .name = "DMNCC", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 77 | .description = "MNCC API for Call Control application", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 78 | .color = "\033[1;39m", |
| 79 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 80 | }, |
| 81 | [DSMS] = { |
| 82 | .name = "DSMS", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 83 | .description = "Layer3 Short Message Service (SMS)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 84 | .color = "\033[1;37m", |
| 85 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 86 | }, |
| 87 | [DPAG] = { |
| 88 | .name = "DPAG", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 89 | .description = "Paging Subsystem", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 90 | .color = "\033[1;38m", |
| 91 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 92 | }, |
| 93 | [DMEAS] = { |
| 94 | .name = "DMEAS", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 95 | .description = "Radio Measurement Processing", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 96 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 97 | }, |
| 98 | [DMI] = { |
| 99 | .name = "DMI", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 100 | .description = "A-bis Input Driver for Signalling", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 101 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 102 | }, |
| 103 | [DMIB] = { |
| 104 | .name = "DMIB", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 105 | .description = "A-bis Input Driver for B-Channels (voice)", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 106 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 107 | }, |
| 108 | [DMUX] = { |
| 109 | .name = "DMUX", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 110 | .description = "A-bis B-Subchannel TRAU Frame Multiplex", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 111 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 112 | }, |
| 113 | [DINP] = { |
| 114 | .name = "DINP", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 115 | .description = "A-bis Intput Subsystem", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 116 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 117 | }, |
| 118 | [DSCCP] = { |
| 119 | .name = "DSCCP", |
| 120 | .description = "SCCP Protocol", |
| 121 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 122 | }, |
| 123 | [DMSC] = { |
| 124 | .name = "DMSC", |
| 125 | .description = "Mobile Switching Center", |
| 126 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 127 | }, |
| 128 | [DMGCP] = { |
| 129 | .name = "DMGCP", |
| 130 | .description = "Media Gateway Control Protocol", |
| 131 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 132 | }, |
| 133 | [DHO] = { |
| 134 | .name = "DHO", |
| 135 | .description = "Hand-Over", |
| 136 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 137 | }, |
| 138 | [DDB] = { |
| 139 | .name = "DDB", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 140 | .description = "Database Layer", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 141 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 142 | }, |
| 143 | [DREF] = { |
| 144 | .name = "DREF", |
| 145 | .description = "Reference Counting", |
| 146 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 147 | }, |
Harald Welte | 2977d67 | 2010-03-28 17:44:55 +0800 | [diff] [blame] | 148 | [DGPRS] = { |
| 149 | .name = "DGPRS", |
| 150 | .description = "GPRS Packet Service", |
| 151 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 152 | }, |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 153 | [DNS] = { |
| 154 | .name = "DNS", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 155 | .description = "GPRS Network Service (NS)", |
Harald Welte | b2e4918 | 2010-05-13 19:47:01 +0200 | [diff] [blame] | 156 | .enabled = 1, .loglevel = LOGL_INFO, |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 157 | }, |
| 158 | [DBSSGP] = { |
| 159 | .name = "DBSSGP", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 160 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 161 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 162 | }, |
Harald Welte | b2e4918 | 2010-05-13 19:47:01 +0200 | [diff] [blame] | 163 | [DLLC] = { |
| 164 | .name = "DLLC", |
| 165 | .description = "GPRS Logical Link Control Protocol (LLC)", |
| 166 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 167 | }, |
| 168 | [DSNDCP] = { |
| 169 | .name = "DSNDCP", |
| 170 | .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)", |
| 171 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 172 | }, |
Holger Hans Peter Freyther | 3d73e0d | 2010-06-15 19:27:25 +0800 | [diff] [blame] | 173 | [DNAT] = { |
| 174 | .name = "DNAT", |
| 175 | .description = "GSM 08.08 NAT/Multipkexer", |
| 176 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 177 | }, |
Daniel Willmann | 1c33d4c | 2011-07-19 12:14:34 +0200 | [diff] [blame] | 178 | [DCTRL] = { |
| 179 | .name = "DCTRL", |
| 180 | .description = "Control interface", |
| 181 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 182 | }, |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 183 | }; |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 184 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 185 | enum log_filter { |
Harald Welte | 332442d | 2010-03-26 21:40:29 +0800 | [diff] [blame] | 186 | _FLT_ALL = LOG_FILTER_ALL, /* libosmocore */ |
| 187 | FLT_IMSI = 1, |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 188 | FLT_NSVC = 2, |
| 189 | FLT_BVC = 3, |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 190 | }; |
| 191 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 192 | static int filter_fn(const struct log_context *ctx, |
| 193 | struct log_target *tar) |
| 194 | { |
Harald Welte | 3bac9a8 | 2010-05-15 23:50:56 +0200 | [diff] [blame] | 195 | struct gsm_subscriber *subscr = ctx->ctx[BSC_CTX_SUBSCR]; |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 196 | const struct gprs_nsvc *nsvc = ctx->ctx[BSC_CTX_NSVC]; |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 197 | const struct gprs_nsvc *bvc = ctx->ctx[BSC_CTX_BVC]; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 198 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 199 | if ((tar->filter_map & (1 << FLT_IMSI)) != 0 |
| 200 | && subscr && strcmp(subscr->imsi, tar->filter_data[FLT_IMSI]) == 0) |
| 201 | return 1; |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 202 | |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 203 | /* Filter on the NS Virtual Connection */ |
| 204 | if ((tar->filter_map & (1 << FLT_NSVC)) != 0 |
| 205 | && nsvc && (nsvc == tar->filter_data[FLT_NSVC])) |
| 206 | return 1; |
| 207 | |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 208 | /* Filter on the NS Virtual Connection */ |
| 209 | if ((tar->filter_map & (1 << FLT_BVC)) != 0 |
| 210 | && bvc && (bvc == tar->filter_data[FLT_BVC])) |
| 211 | return 1; |
| 212 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | const struct log_info log_info = { |
| 217 | .filter_fn = filter_fn, |
| 218 | .cat = default_categories, |
| 219 | .num_cat = ARRAY_SIZE(default_categories), |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 220 | }; |
| 221 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 222 | void log_set_imsi_filter(struct log_target *target, const char *imsi) |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 223 | { |
| 224 | if (imsi) { |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 225 | target->filter_map |= (1 << FLT_IMSI); |
| 226 | target->filter_data[FLT_IMSI] = talloc_strdup(target, imsi); |
| 227 | } else if (target->filter_data[FLT_IMSI]) { |
| 228 | target->filter_map &= ~(1 << FLT_IMSI); |
| 229 | talloc_free(target->filter_data[FLT_IMSI]); |
| 230 | target->filter_data[FLT_IMSI] = NULL; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 231 | } |
| 232 | } |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 233 | |
Holger Hans Peter Freyther | d92f9af | 2010-05-23 20:59:55 +0800 | [diff] [blame] | 234 | void log_set_nsvc_filter(struct log_target *target, struct gprs_nsvc *nsvc) |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 235 | { |
| 236 | if (nsvc) { |
| 237 | target->filter_map |= (1 << FLT_NSVC); |
| 238 | target->filter_data[FLT_NSVC] = nsvc; |
| 239 | } else if (target->filter_data[FLT_NSVC]) { |
| 240 | target->filter_map = ~(1 << FLT_NSVC); |
| 241 | target->filter_data[FLT_NSVC] = NULL; |
| 242 | } |
| 243 | } |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 244 | |
Holger Hans Peter Freyther | d92f9af | 2010-05-23 20:59:55 +0800 | [diff] [blame] | 245 | void log_set_bvc_filter(struct log_target *target, struct bssgp_bvc_ctx *bctx) |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 246 | { |
| 247 | if (bctx) { |
| 248 | target->filter_map |= (1 << FLT_BVC); |
| 249 | target->filter_data[FLT_BVC] = bctx; |
| 250 | } else if (target->filter_data[FLT_NSVC]) { |
| 251 | target->filter_map = ~(1 << FLT_BVC); |
| 252 | target->filter_data[FLT_BVC] = NULL; |
| 253 | } |
| 254 | } |