Ivan Kluchnikov | 6043718 | 2012-05-24 22:07:15 +0400 | [diff] [blame] | 1 | /* gprs_debug.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <stdarg.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
| 24 | #include <strings.h> |
| 25 | #include <time.h> |
| 26 | #include <errno.h> |
| 27 | |
| 28 | #include <osmocom/core/talloc.h> |
| 29 | #include <osmocom/core/utils.h> |
| 30 | #include <osmocom/core/logging.h> |
Ivan Kluchnikov | 6043718 | 2012-05-24 22:07:15 +0400 | [diff] [blame] | 31 | #include <gprs_debug.h> |
| 32 | |
| 33 | /* default categories */ |
| 34 | |
| 35 | static const struct log_info_cat default_categories[] = { |
Andreas Eversberg | 0e40309 | 2012-07-06 11:04:57 +0200 | [diff] [blame] | 36 | {"DCSN1", "\033[1;31m", "Concrete Syntax Notation One (CSN1)", LOGL_INFO, 0}, |
| 37 | {"DL1IF", "\033[1;32m", "GPRS PCU L1 interface (L1IF)", LOGL_INFO, 1}, |
Andreas Eversberg | d87b468 | 2012-11-04 12:51:42 +0100 | [diff] [blame] | 38 | {"DRLCMAC", "\033[0;33m", "GPRS RLC/MAC layer (RLCMAC)", LOGL_NOTICE, 1}, |
| 39 | {"DRLCMACDATA", "\033[0;33m", "GPRS RLC/MAC layer Data (RLCMAC)", LOGL_NOTICE, 1}, |
| 40 | {"DRLCMACDL", "\033[1;33m", "GPRS RLC/MAC layer Downlink (RLCMAC)", LOGL_NOTICE, 1}, |
| 41 | {"DRLCMACUL", "\033[1;36m", "GPRS RLC/MAC layer Uplink (RLCMAC)", LOGL_NOTICE, 1}, |
| 42 | {"DRLCMACSCHED", "\033[0;36m", "GPRS RLC/MAC layer Scheduling (RLCMAC)", LOGL_NOTICE, 1}, |
Andreas Eversberg | 050ace2 | 2013-03-16 16:22:02 +0100 | [diff] [blame] | 43 | {"DRLCMACMEAS", "\033[1;31m", "GPRS RLC/MAC layer Measurements (RLCMAC)", LOGL_INFO, 1}, |
Andreas Eversberg | d87b468 | 2012-11-04 12:51:42 +0100 | [diff] [blame] | 44 | {"DBSSGP","\033[1;34m", "GPRS BSS Gateway Protocol (BSSGP)", LOGL_INFO , 1}, |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 45 | {"DPCU", "\033[1;35m", "GPRS Packet Control Unit (PCU)", LOGL_NOTICE, 1}, |
Ivan Kluchnikov | 6043718 | 2012-05-24 22:07:15 +0400 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | enum { |
| 49 | _FLT_ALL = LOG_FILTER_ALL, /* libosmocore */ |
| 50 | FLT_IMSI = 1, |
| 51 | FLT_NSVC = 2, |
| 52 | FLT_BVC = 3, |
| 53 | }; |
| 54 | |
| 55 | static int filter_fn(const struct log_context *ctx, |
| 56 | struct log_target *tar) |
| 57 | { |
Ivan Kluchnikov | 6043718 | 2012-05-24 22:07:15 +0400 | [diff] [blame] | 58 | const struct gprs_nsvc *nsvc = (const struct gprs_nsvc*)ctx->ctx[BSC_CTX_NSVC]; |
| 59 | const struct gprs_nsvc *bvc = (const struct gprs_nsvc*)ctx->ctx[BSC_CTX_BVC]; |
| 60 | |
Ivan Kluchnikov | 6043718 | 2012-05-24 22:07:15 +0400 | [diff] [blame] | 61 | /* Filter on the NS Virtual Connection */ |
| 62 | if ((tar->filter_map & (1 << FLT_NSVC)) != 0 |
| 63 | && nsvc && (nsvc == tar->filter_data[FLT_NSVC])) |
| 64 | return 1; |
| 65 | |
| 66 | /* Filter on the BVC */ |
| 67 | if ((tar->filter_map & (1 << FLT_BVC)) != 0 |
| 68 | && bvc && (bvc == tar->filter_data[FLT_BVC])) |
| 69 | return 1; |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | const struct log_info gprs_log_info = { |
| 75 | filter_fn, |
| 76 | (struct log_info_cat*)default_categories, |
| 77 | ARRAY_SIZE(default_categories), |
| 78 | }; |