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 |
| 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> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <string.h> |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 27 | #include <strings.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 28 | #include <time.h> |
Harald Welte (local) | b79bdd9 | 2009-12-26 19:45:22 +0100 | [diff] [blame] | 29 | #include <errno.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 30 | |
Harald Welte | dfe6c7d | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 31 | #include <osmocore/talloc.h> |
Harald Welte | 2e411c7 | 2010-03-01 21:59:06 +0100 | [diff] [blame] | 32 | #include <osmocore/utils.h> |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 33 | #include <osmocore/logging.h> |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 34 | #include <openbsc/gsm_data.h> |
| 35 | #include <openbsc/gsm_subscriber.h> |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 36 | #include <openbsc/debug.h> |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 37 | |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 38 | /* default categories */ |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 39 | static const struct log_info_cat default_categories[] = { |
| 40 | [DRLL] = { |
| 41 | .name = "DRLL", |
| 42 | .description = "Radio Link Layer", |
| 43 | .color = "\033[1;31m", |
| 44 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 45 | }, |
| 46 | [DCC] = { |
| 47 | .name = "DCC", |
| 48 | .description = "Call Control", |
| 49 | .color = "\033[1;32m", |
| 50 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 51 | }, |
| 52 | [DMM] = { |
| 53 | .name = "DMM", |
| 54 | .description = "Mobility Management", |
| 55 | .color = "\033[1;33m", |
| 56 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 57 | }, |
| 58 | [DRR] = { |
| 59 | .name = "DRR", |
| 60 | .description = "Radio Resource", |
| 61 | .color = "\033[1;34m", |
| 62 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 63 | }, |
| 64 | [DRSL] = { |
| 65 | .name = "DRSL", |
| 66 | .description = "Radio Siganlling Link", |
| 67 | .color = "\033[1;35m", |
| 68 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 69 | }, |
| 70 | [DNM] = { |
| 71 | .name = "DNM", |
| 72 | .description = "Network Management (OML)", |
| 73 | .color = "\033[1;36m", |
| 74 | .enabled = 1, .loglevel = LOGL_INFO, |
| 75 | }, |
| 76 | [DMNCC] = { |
| 77 | .name = "DMNCC", |
| 78 | .description = "BSC<->MSC interface", |
| 79 | .color = "\033[1;39m", |
| 80 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 81 | }, |
| 82 | [DSMS] = { |
| 83 | .name = "DSMS", |
| 84 | .description = "Short Message Service", |
| 85 | .color = "\033[1;37m", |
| 86 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 87 | }, |
| 88 | [DPAG] = { |
| 89 | .name = "DPAG", |
| 90 | .description = "Paging", |
| 91 | .color = "\033[1;38m", |
| 92 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 93 | }, |
| 94 | [DMEAS] = { |
| 95 | .name = "DMEAS", |
| 96 | .description = "Measurement Processing", |
| 97 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 98 | }, |
| 99 | [DMI] = { |
| 100 | .name = "DMI", |
| 101 | .description = "mISDN Input Driver", |
| 102 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 103 | }, |
| 104 | [DMIB] = { |
| 105 | .name = "DMIB", |
| 106 | .description = "mISDN B-Channels", |
| 107 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 108 | }, |
| 109 | [DMUX] = { |
| 110 | .name = "DMUX", |
| 111 | .description = "TRAU Frame Multiplex", |
| 112 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 113 | }, |
| 114 | [DINP] = { |
| 115 | .name = "DINP", |
| 116 | .description = "Input Driver", |
| 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", |
| 141 | .description = "Database", |
| 142 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 143 | }, |
| 144 | [DREF] = { |
| 145 | .name = "DREF", |
| 146 | .description = "Reference Counting", |
| 147 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 148 | }, |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 149 | }; |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 150 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 151 | enum log_ctxt { |
| 152 | CTX_SUBSCRIBER, |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 155 | enum log_filter { |
Harald Welte | 332442d | 2010-03-26 21:40:29 +0800 | [diff] [blame] | 156 | _FLT_ALL = LOG_FILTER_ALL, /* libosmocore */ |
| 157 | FLT_IMSI = 1, |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 158 | }; |
| 159 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 160 | static int filter_fn(const struct log_context *ctx, |
| 161 | struct log_target *tar) |
| 162 | { |
| 163 | struct gsm_subscriber *subscr = ctx->ctx[CTX_SUBSCRIBER]; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 164 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 165 | if ((tar->filter_map & (1 << FLT_IMSI)) != 0 |
| 166 | && subscr && strcmp(subscr->imsi, tar->filter_data[FLT_IMSI]) == 0) |
| 167 | return 1; |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 168 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | const struct log_info log_info = { |
| 173 | .filter_fn = filter_fn, |
| 174 | .cat = default_categories, |
| 175 | .num_cat = ARRAY_SIZE(default_categories), |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 178 | 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] | 179 | { |
| 180 | if (imsi) { |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 181 | target->filter_map |= (1 << FLT_IMSI); |
| 182 | target->filter_data[FLT_IMSI] = talloc_strdup(target, imsi); |
| 183 | } else if (target->filter_data[FLT_IMSI]) { |
| 184 | target->filter_map &= ~(1 << FLT_IMSI); |
| 185 | talloc_free(target->filter_data[FLT_IMSI]); |
| 186 | target->filter_data[FLT_IMSI] = NULL; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 187 | } |
| 188 | } |