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