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> |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 33 | #include <osmocom/gprs/gprs_msgb.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", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 42 | .description = "A-bis Radio Link Layer (RLL)", |
Harald Welte | dc5062b | 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 | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 48 | .description = "Layer3 Call Control (CC)", |
Harald Welte | dc5062b | 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 | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 54 | .description = "Layer3 Mobility Management (MM)", |
Harald Welte | dc5062b | 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 | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 60 | .description = "Layer3 Radio Resource (RR)", |
Harald Welte | dc5062b | 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 | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 66 | .description = "A-bis Radio Siganlling Link (RSL)", |
Harald Welte | dc5062b | 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 | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 72 | .description = "A-bis Network Management / O&M (NM/OML)", |
Harald Welte | dc5062b | 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 | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 78 | .description = "MNCC API for Call Control application", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 79 | .color = "\033[1;39m", |
| 80 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 81 | }, |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 82 | [DPAG] = { |
| 83 | .name = "DPAG", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 84 | .description = "Paging Subsystem", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 85 | .color = "\033[1;38m", |
| 86 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 87 | }, |
| 88 | [DMEAS] = { |
| 89 | .name = "DMEAS", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 90 | .description = "Radio Measurement Processing", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 91 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 92 | }, |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 93 | [DSCCP] = { |
| 94 | .name = "DSCCP", |
| 95 | .description = "SCCP Protocol", |
| 96 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 97 | }, |
| 98 | [DMSC] = { |
| 99 | .name = "DMSC", |
| 100 | .description = "Mobile Switching Center", |
| 101 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 102 | }, |
| 103 | [DMGCP] = { |
| 104 | .name = "DMGCP", |
| 105 | .description = "Media Gateway Control Protocol", |
| 106 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 107 | }, |
| 108 | [DHO] = { |
| 109 | .name = "DHO", |
| 110 | .description = "Hand-Over", |
| 111 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 112 | }, |
| 113 | [DDB] = { |
| 114 | .name = "DDB", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 115 | .description = "Database Layer", |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 116 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 117 | }, |
| 118 | [DREF] = { |
| 119 | .name = "DREF", |
| 120 | .description = "Reference Counting", |
| 121 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 122 | }, |
Harald Welte | 2977d67 | 2010-03-28 17:44:55 +0800 | [diff] [blame] | 123 | [DGPRS] = { |
| 124 | .name = "DGPRS", |
| 125 | .description = "GPRS Packet Service", |
| 126 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 127 | }, |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 128 | [DNS] = { |
| 129 | .name = "DNS", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 130 | .description = "GPRS Network Service (NS)", |
Harald Welte | b2e4918 | 2010-05-13 19:47:01 +0200 | [diff] [blame] | 131 | .enabled = 1, .loglevel = LOGL_INFO, |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 132 | }, |
| 133 | [DBSSGP] = { |
| 134 | .name = "DBSSGP", |
Harald Welte | f171a6e | 2010-05-11 10:51:30 +0200 | [diff] [blame] | 135 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 136 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 137 | }, |
Harald Welte | b2e4918 | 2010-05-13 19:47:01 +0200 | [diff] [blame] | 138 | [DLLC] = { |
| 139 | .name = "DLLC", |
| 140 | .description = "GPRS Logical Link Control Protocol (LLC)", |
| 141 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 142 | }, |
| 143 | [DSNDCP] = { |
| 144 | .name = "DSNDCP", |
| 145 | .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)", |
| 146 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 147 | }, |
Holger Hans Peter Freyther | 3d73e0d | 2010-06-15 19:27:25 +0800 | [diff] [blame] | 148 | [DNAT] = { |
| 149 | .name = "DNAT", |
Holger Hans Peter Freyther | 30a3d2f | 2013-01-10 23:46:17 +0100 | [diff] [blame] | 150 | .description = "GSM 08.08 NAT/Multiplexer", |
Holger Hans Peter Freyther | 3d73e0d | 2010-06-15 19:27:25 +0800 | [diff] [blame] | 151 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 152 | }, |
Daniel Willmann | 1c33d4c | 2011-07-19 12:14:34 +0200 | [diff] [blame] | 153 | [DCTRL] = { |
| 154 | .name = "DCTRL", |
| 155 | .description = "Control interface", |
| 156 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 157 | }, |
Harald Welte | f1033cc | 2012-11-08 16:14:37 +0100 | [diff] [blame] | 158 | [DSMPP] = { |
| 159 | .name = "DSMPP", |
| 160 | .description = "SMPP interface for external SMS apps", |
| 161 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 162 | }, |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 163 | }; |
Holger Freyther | 32636e8 | 2008-12-27 11:07:15 +0000 | [diff] [blame] | 164 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 165 | enum log_filter { |
Harald Welte | 332442d | 2010-03-26 21:40:29 +0800 | [diff] [blame] | 166 | _FLT_ALL = LOG_FILTER_ALL, /* libosmocore */ |
| 167 | FLT_IMSI = 1, |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 168 | FLT_NSVC = 2, |
| 169 | FLT_BVC = 3, |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 172 | static int filter_fn(const struct log_context *ctx, |
| 173 | struct log_target *tar) |
| 174 | { |
Harald Welte | 3bac9a8 | 2010-05-15 23:50:56 +0200 | [diff] [blame] | 175 | struct gsm_subscriber *subscr = ctx->ctx[BSC_CTX_SUBSCR]; |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 176 | const struct gprs_nsvc *nsvc = ctx->ctx[GPRS_CTX_NSVC]; |
| 177 | const struct gprs_nsvc *bvc = ctx->ctx[GPRS_CTX_BVC]; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 178 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 179 | if ((tar->filter_map & (1 << FLT_IMSI)) != 0 |
Holger Hans Peter Freyther | 6995f24 | 2014-12-28 18:54:32 +0100 | [diff] [blame] | 180 | && subscr && subscr == tar->filter_data[FLT_IMSI]) |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 181 | return 1; |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 182 | |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 183 | /* Filter on the NS Virtual Connection */ |
| 184 | if ((tar->filter_map & (1 << FLT_NSVC)) != 0 |
| 185 | && nsvc && (nsvc == tar->filter_data[FLT_NSVC])) |
| 186 | return 1; |
| 187 | |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 188 | /* Filter on the NS Virtual Connection */ |
| 189 | if ((tar->filter_map & (1 << FLT_BVC)) != 0 |
| 190 | && bvc && (bvc == tar->filter_data[FLT_BVC])) |
| 191 | return 1; |
| 192 | |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | const struct log_info log_info = { |
| 197 | .filter_fn = filter_fn, |
| 198 | .cat = default_categories, |
| 199 | .num_cat = ARRAY_SIZE(default_categories), |
Holger Freyther | d546e31 | 2008-12-27 12:03:07 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
Holger Hans Peter Freyther | 6995f24 | 2014-12-28 18:54:32 +0100 | [diff] [blame] | 202 | void log_set_imsi_filter(struct log_target *target, struct gsm_subscriber *subscr) |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 203 | { |
Holger Hans Peter Freyther | 6995f24 | 2014-12-28 18:54:32 +0100 | [diff] [blame] | 204 | /* free the old data */ |
| 205 | if (target->filter_data[FLT_IMSI]) { |
| 206 | subscr_put(target->filter_data[FLT_IMSI]); |
Harald Welte | dc5062b | 2010-03-26 21:28:59 +0800 | [diff] [blame] | 207 | target->filter_data[FLT_IMSI] = NULL; |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 208 | } |
Holger Hans Peter Freyther | 6995f24 | 2014-12-28 18:54:32 +0100 | [diff] [blame] | 209 | |
| 210 | if (subscr) { |
| 211 | target->filter_map |= (1 << FLT_IMSI); |
| 212 | target->filter_data[FLT_IMSI] = subscr_get(subscr); |
| 213 | } else { |
| 214 | target->filter_map &= ~(1 << FLT_IMSI); |
| 215 | } |
Holger Hans Peter Freyther | b61e3b2 | 2009-12-22 22:32:51 +0100 | [diff] [blame] | 216 | } |