Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.08 KB | None | 0 0
  1. diff -u --recursive --new-file 1/include/openbsc/gsm_data.h 2/include/openbsc/gsm_data.h
  2. --- 1/include/openbsc/gsm_data.h 2010-08-17 11:59:24.000000000 +0200
  3. +++ 2/include/openbsc/gsm_data.h 2010-09-13 11:37:40.412701000 +0200
  4. @@ -305,6 +305,10 @@
  5. } abis_ip;
  6.  
  7. struct gsm_subscriber_connection *conn;
  8. +
  9. + // Diese ID ist nötig da das conn struct nicht immer initialisiert ist
  10. +#warning NICK
  11. + long MYSQL_ID;
  12. };
  13.  
  14. struct gsm_e1_subslot {
  15. diff -u --recursive --new-file 1/src/abis_rsl.c 2/src/abis_rsl.c
  16. --- 1/src/abis_rsl.c 2010-08-17 11:59:24.000000000 +0200
  17. +++ 2/src/abis_rsl.c 2010-09-13 11:34:13.072700000 +0200
  18. @@ -907,22 +907,36 @@
  19. DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta);
  20. }
  21.  
  22. - if (mr->flags & MEAS_REP_F_UL_DTX)
  23. +#warning Nick
  24. + char* FLAG = "";
  25. +
  26. + if (mr->flags & MEAS_REP_F_UL_DTX) {
  27. DEBUGPC(DMEAS, "DTXu ");
  28. - if (mr->flags & MEAS_REP_F_BA1)
  29. + FLAG = "DTXu";
  30. + }
  31. + if (mr->flags & MEAS_REP_F_BA1) {
  32. DEBUGPC(DMEAS, "BA1 ");
  33. - if (!(mr->flags & MEAS_REP_F_DL_VALID))
  34. + FLAG = "BA1";
  35. + }
  36. + if (!(mr->flags & MEAS_REP_F_DL_VALID)) {
  37. DEBUGPC(DMEAS, "NOT VALID ");
  38. - else
  39. + FLAG = "NOT VALID";
  40. + } else
  41. print_meas_rep_uni(&mr->dl, "dl");
  42. -
  43. +#warning NICK
  44. DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell);
  45. +
  46. + int ms_timing_offset = (mr->flags & MEAS_REP_F_MS_TO) ? mr->ms_timing_offset : -1;
  47. +
  48. if (mr->num_cell == 7)
  49. return;
  50. for (i = 0; i < mr->num_cell; i++) {
  51. struct gsm_meas_rep_cell *mrc = &mr->cell[i];
  52. DEBUGP(DMEAS, "IDX=%u ARFCN=%u BSIC=%u => %d dBm\n",
  53. mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));
  54. + if (mr->flags & MEAS_REP_F_DL_VALID) {
  55. + UpdateMeasurementResult(get_last_insert_id(), i, mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));
  56. + }
  57. }
  58. }
  59.  
  60. @@ -1233,6 +1247,14 @@
  61. "r=%s ra=0x%02x\n", gsm_lchan_name(lchan), arfcn, subch,
  62. gsm_lchant_name(lchan->type), gsm_chreq_name(chreq_reason),
  63. rqd_ref->ra);
  64. +
  65. +#warning NICK
  66. + // Jedes Mal wenn ein Channel angefordert wird, wird eine "leere Hülse" in die Datenbank eingetragen, welche später befüllt wird.
  67. + InsertEmptyAction();
  68. + lchan->MYSQL_ID = get_last_insert_id();
  69. +
  70. + insertUsedBTS(lchan->MYSQL_ID, bts->cell_identity, "Channel Request");
  71. +
  72. return 0;
  73. }
  74.  
  75. diff -u --recursive --new-file 1/src/bsc_hack.c 2/src/bsc_hack.c
  76. --- 1/src/bsc_hack.c 2010-08-17 11:59:24.000000000 +0200
  77. +++ 2/src/bsc_hack.c 2010-09-13 12:29:56.572705000 +0200
  78. @@ -207,6 +207,11 @@
  79. .go_parent_cb = bsc_vty_go_parent,
  80. };
  81.  
  82. +#warning Nick
  83. +const char* dbLogging = "test";
  84. +const char* dbUsername = "root";
  85. +const char* dbPassword = "openbsc";
  86. +
  87. int main(int argc, char **argv)
  88. {
  89. int rc;
  90. @@ -256,6 +261,19 @@
  91. }
  92. printf("DB: Database prepared.\n");
  93.  
  94. +#warning NICK_MYSQL
  95. + if (dbLogging_init(dbLogging, dbUsername, dbPassword)) { // makefile.am muss editiert werden: libmsc_a_SOURCES = gsm_subscriber.c db.c dbLogging.c
  96. + printf("DB Logging: Failed to init database. Please check the option settings.\n");
  97. + return -1;
  98. + }
  99. + printf("DB Logging: Database initialized.\n");
  100. + if (dbLogging_prepare()) {
  101. + printf("DB Logging: Failed to prepare database.\n");
  102. + return -1;
  103. + }
  104. + printf("DB Logging: Database prepared.\n");
  105. +#warning NICK_MYSQL
  106. +
  107. /* setup the timer */
  108. db_sync_timer.cb = db_sync_timer_cb;
  109. db_sync_timer.data = NULL;
  110. diff -u --recursive --new-file 1/src/dbLogging.c 2/src/dbLogging.c
  111. --- 1/src/dbLogging.c 1970-01-01 01:00:00.000000000 +0100
  112. +++ 2/src/dbLogging.c 2010-08-31 13:42:38.203621000 +0200
  113. @@ -0,0 +1,217 @@
  114. +/* Simple HLR/VLR database backend using dbi */
  115. +/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
  116. + * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
  117. + * (C) 2009 by Harald Welte <laforge@gnumonks.org>
  118. + * All Rights Reserved
  119. + *
  120. + * This program is free software; you can redistribute it and/or modify
  121. + * it under the terms of the GNU General Public License as published by
  122. + * the Free Software Foundation; either version 2 of the License, or
  123. + * (at your option) any later version.
  124. + *
  125. + * This program is distributed in the hope that it will be useful,
  126. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  127. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  128. + * GNU General Public License for more details.
  129. + *
  130. + * You should have received a copy of the GNU General Public License along
  131. + * with this program; if not, write to the Free Software Foundation, Inc.,
  132. + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  133. + *
  134. + */
  135. +
  136. +#include <stdint.h>
  137. +#include <inttypes.h>
  138. +#include <libgen.h>
  139. +#include <stdio.h>
  140. +#include <stdlib.h>
  141. +#include <string.h>
  142. +#include <errno.h>
  143. +#include <dbi/dbi.h>
  144. +
  145. +#include <openbsc/gsm_data.h>
  146. +#include <openbsc/gsm_04_11.h>
  147. +#include <openbsc/db.h>
  148. +#include <osmocore/talloc.h>
  149. +#include <openbsc/debug.h>
  150. +#include <osmocore/statistics.h>
  151. +#include <osmocore/rate_ctr.h>
  152. +
  153. +static dbi_conn LogConn;
  154. +
  155. +static char *create_stmts[] = { "CREATE TABLE IF NOT EXISTS action ("
  156. + "id BIGINT NOT NULL AUTO_INCREMENT,"
  157. + "cur_timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
  158. + "actionID TINYINT DEFAULT NULL,"
  159. + "IMSI varchar(100) DEFAULT NULL,"
  160. + "PRIMARY KEY (id)"
  161. + ")", "CREATE TABLE IF NOT EXISTS measurementResults ("
  162. + "id INT NOT NULL AUTO_INCREMENT,"
  163. + "cur_timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
  164. + "actionRefID BIGINT DEFAULT NULL,"
  165. + "RXL_FULL_ul int DEFAULT NULL,"
  166. + "RXL_SUB_ul int DEFAULT NULL,"
  167. + "RXQ_FULL_ul int DEFAULT NULL,"
  168. + "RXQ_SUB_ul int DEFAULT NULL,"
  169. + "BS_POWER int DEFAULT NULL,"
  170. + "MS_TO int DEFAULT NULL,"
  171. + "FLAG varchar(100) DEFAULT NULL,"
  172. + "RXL_FULL_dl int DEFAULT NULL,"
  173. + "RXL_SUB_dl int DEFAULT NULL,"
  174. + "RXQ_FULL_dl int DEFAULT NULL,"
  175. + "RXQ_SUB_dl int DEFAULT NULL,"
  176. + "NUM_NEIGH int DEFAULT NULL,"
  177. +
  178. + "IDX_0 int DEFAULT NULL,"
  179. + "ARFCN_0 int DEFAULT NULL,"
  180. + "BSIC_0 int DEFAULT NULL,"
  181. + "rxlev_0 int DEFAULT NULL,"
  182. +
  183. + "IDX_1 int DEFAULT NULL,"
  184. + "ARFCN_1 int DEFAULT NULL,"
  185. + "BSIC_1 int DEFAULT NULL,"
  186. + "rxlev_1 int DEFAULT NULL,"
  187. +
  188. + "IDX_2 int DEFAULT NULL,"
  189. + "ARFCN_2 int DEFAULT NULL,"
  190. + "BSIC_2 int DEFAULT NULL,"
  191. + "rxlev_2 int DEFAULT NULL,"
  192. +
  193. + "IDX_3 int DEFAULT NULL,"
  194. + "ARFCN_3 int DEFAULT NULL,"
  195. + "BSIC_3 int DEFAULT NULL,"
  196. + "rxlev_3 int DEFAULT NULL,"
  197. +
  198. + "IDX_4 int DEFAULT NULL,"
  199. + "ARFCN_4 int DEFAULT NULL,"
  200. + "BSIC_4 int DEFAULT NULL,"
  201. + "rxlev_4 int DEFAULT NULL,"
  202. +
  203. + "IDX_5 int DEFAULT NULL,"
  204. + "ARFCN_5 int DEFAULT NULL,"
  205. + "BSIC_5 int DEFAULT NULL,"
  206. + "rxlev_5 int DEFAULT NULL,"
  207. +
  208. + "PRIMARY KEY (id)"
  209. + ")", "CREATE TABLE IF NOT EXISTS usedBTS ("
  210. + "id BIGINT NOT NULL AUTO_INCREMENT,"
  211. + "cur_timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,"
  212. + "actionRefID BIGINT DEFAULT NULL,"
  213. + "bts int DEFAULT NULL,"
  214. + "cause varchar(100) DEFAULT NULL,"
  215. + "PRIMARY KEY (id)"
  216. + ")", "CREATE TABLE IF NOT EXISTS actionIdentifier ("
  217. + "id TINYINT NOT NULL,"
  218. + "Name varchar(100) NOT NULL,"
  219. + "PRIMARY KEY (id),"
  220. + "UNIQUE KEY id (id)"
  221. + ")" };
  222. +
  223. +void dbLogging_error_func(dbi_conn conn, void *data) {
  224. + const char *msg;
  225. + dbi_conn_error(conn, &msg);
  226. + LOGP(DDB, LOGL_ERROR, "DBI Logging: %s\n", msg);
  227. +}
  228. +
  229. +int dbLogging_init(const char *dbName, const char *user, const char *password) {
  230. + dbi_initialize(NULL);
  231. +
  232. + LogConn = dbi_conn_new("mysql");
  233. +
  234. + if (LogConn == NULL) {
  235. + LOGP(DDB, LOGL_FATAL, "Failed to create connection to Logging Database.\n");
  236. + return 1;
  237. + }
  238. +
  239. + dbi_conn_error_handler(LogConn, dbLogging_error_func, NULL);
  240. +
  241. + dbi_conn_set_option(LogConn, "host", "localhost");
  242. + dbi_conn_set_option(LogConn, "username", strdup(user));
  243. + dbi_conn_set_option(LogConn, "password", strdup(password));
  244. + dbi_conn_set_option(LogConn, "dbname", strdup(dbName));
  245. + dbi_conn_set_option(LogConn, "encoding", "latin1");
  246. +
  247. + if (dbi_conn_connect(LogConn) < 0)
  248. + goto out_err;
  249. +
  250. + return 0;
  251. +
  252. + out_err: return -1;
  253. +}
  254. +
  255. +int dbLogging_prepare() {
  256. + dbi_result result;
  257. + int i;
  258. +
  259. + for (i = 0; i < ARRAY_SIZE(create_stmts); i++) {
  260. + result = dbi_conn_query(LogConn, create_stmts[i]);
  261. + if (!result) {
  262. + LOGP(DDB, LOGL_ERROR, "Failed to create some table.\n");
  263. + return 1;
  264. + }
  265. + dbi_result_free(result);
  266. + }
  267. +
  268. + InsertActionIdentifiers();
  269. +
  270. + return 0;
  271. +}
  272. +
  273. +int dbLogging_fini() {
  274. + dbi_conn_close(LogConn);
  275. + dbi_shutdown();
  276. +
  277. + return 0;
  278. +}
  279. +
  280. +long get_last_insert_id() {
  281. + dbi_result result = dbi_conn_queryf(LogConn, "select last_insert_id();");
  282. + dbi_result_first_row(result);
  283. +
  284. + long _result = dbi_result_get_longlong(result, "last_insert_id()");
  285. +
  286. + dbi_result_free(result);
  287. +
  288. + return _result;
  289. +}
  290. +
  291. +void InsertActionIdentifiers() {
  292. + dbi_result_free(dbi_conn_query(LogConn, "insert into actionIdentifier(id, Name) VALUES(1, 'Location Update');"));
  293. + dbi_result_free(dbi_conn_query(LogConn, "insert into actionIdentifier(id, Name) VALUES(2, 'Call');"));
  294. +}
  295. +
  296. +void InsertEmptyAction() {
  297. + dbi_result_free(dbi_conn_query(LogConn, "insert into action(actionID) VALUES(-1);"));
  298. +}
  299. +
  300. +void UpdateActionID(long id, int ActionID) {
  301. + dbi_result_free(dbi_conn_queryf(LogConn, "UPDATE action SET actionID=%i where id=%i;", ActionID, id));
  302. +}
  303. +
  304. +void UpdateActionIMSI(long id, char* IMSI) {
  305. + dbi_result_free(dbi_conn_queryf(LogConn, "UPDATE action SET IMSI='%s' where id=%i;", IMSI, id));
  306. +}
  307. +
  308. +void InsertMeasurementResult(long actionRefID, int RXL_FULL_ul, int RXL_SUB_ul, int RXQ_FULL_ul, int RXQ_SUB_ul, int BS_POWER, int MS_TO, char* FLAG, int RXL_FULL_dl, int RXL_SUB_dl, int RXQ_FULL_dl, int RXQ_SUB_dl, int NUM_NEIGH) {
  309. + dbi_result_free(dbi_conn_queryf(LogConn, "insert into measurementResults(actionRefID, RXL_FULL_ul , RXL_SUB_ul , RXQ_FULL_ul, RXQ_SUB_ul , BS_POWER , MS_TO , FLAG , RXL_FULL_dl , RXL_SUB_dl , RXQ_FULL_dl , RXQ_SUB_dl , NUM_NEIGH) VALUES(%i, %i, %i, %i, %i, %i, %i, '%s', %i, %i, %i, %i, %i);", actionRefID, RXL_FULL_ul, RXL_SUB_ul, RXQ_FULL_ul, RXQ_SUB_ul, BS_POWER, MS_TO, FLAG, RXL_FULL_dl, RXL_SUB_dl, RXQ_FULL_dl, RXQ_SUB_dl, NUM_NEIGH));
  310. +}
  311. +
  312. +void UpdateMeasurementResult(long actionRefID, int index, int neigh_idx, int arfcn, int bsic, int rxlev) {
  313. + char IDX_[100];
  314. + sprintf(IDX_, "IDX_%i", index);
  315. +
  316. + char ARFCN_[100];
  317. + sprintf(ARFCN_, "ARFCN_%i", index);
  318. +
  319. + char BSIC_[100];
  320. + sprintf(BSIC_, "BSIC_%i", index);
  321. +
  322. + char rxlev_[100];
  323. + sprintf(rxlev_, "rxlev_%i", index);
  324. +
  325. + dbi_result_free(dbi_conn_queryf(LogConn, "UPDATE measurementResults SET %s=%i, %s=%i, %s=%i, %s=%i where id=%i;", IDX_, neigh_idx, ARFCN_, arfcn, BSIC_, bsic, rxlev_, rxlev, actionRefID));
  326. +}
  327. +
  328. +void insertUsedBTS(long actionRefID, int BTS, char* cause) {
  329. + dbi_result_free(dbi_conn_queryf(LogConn, "insert into usedBTS(actionRefID, bts, cause) values(%i, %i, '%s');", actionRefID, BTS, cause));
  330. +}
  331. diff -u --recursive --new-file 1/src/gsm_04_08.c 2/src/gsm_04_08.c
  332. --- 1/src/gsm_04_08.c 2010-08-17 11:59:24.000000000 +0200
  333. +++ 2/src/gsm_04_08.c 2010-09-13 11:43:01.729200000 +0200
  334. @@ -349,6 +349,9 @@
  335. subscr_name(conn->subscr) : "unknown",
  336. bts->location_area_code, bts->nr);
  337.  
  338. +#warning NICK
  339. + UpdateActionIMSI(conn->lchan->MYSQL_ID, conn->subscr->imsi);
  340. +
  341. return gsm48_conn_sendmsg(msg, conn, NULL);
  342. }
  343.  
  344. @@ -376,6 +379,9 @@
  345.  
  346. DEBUGP(DMM, "-> LOCATION UPDATE ACCEPT\n");
  347.  
  348. +#warning NICK_MYSQL
  349. + UpdateActionIMSI(conn->lchan->MYSQL_ID, conn->subscr->imsi);
  350. +
  351. counter_inc(bts->network->stats.loc_upd_resp.accept);
  352.  
  353. return gsm48_conn_sendmsg(msg, conn, NULL);
  354. @@ -490,6 +496,13 @@
  355.  
  356. gsm48_mi_to_string(mi_string, sizeof(mi_string), lu->mi, lu->mi_len);
  357.  
  358. +#warning NICK - muss hier oben sein !
  359. + UpdateActionID(conn->lchan->MYSQL_ID, 1);
  360. + if (mi_type == GSM_MI_TYPE_IMSI) {
  361. + DEBUGPC(DMM, "NICK MYSQL: IMSI already available in Updating Request: %s \n", mi_string);
  362. + UpdateActionIMSI(conn->lchan->MYSQL_ID, mi_string);
  363. + }
  364. +
  365. DEBUGPC(DMM, "mi_type=0x%02x MI(%s) type=%s ", mi_type, mi_string,
  366. lupd_name(lu->type));
  367.  
  368. diff -u --recursive --new-file 1/src/gsm_04_11.c 2/src/gsm_04_11.c
  369. --- 1/src/gsm_04_11.c 2010-08-17 11:59:24.000000000 +0200
  370. +++ 2/src/gsm_04_11.c 2010-09-13 11:49:21.025201000 +0200
  371. @@ -602,6 +602,10 @@
  372.  
  373. gsms->sender = subscr_get(conn->subscr);
  374.  
  375. +#warning NICK
  376. + UpdateActionID(conn->lchan->MYSQL_ID, 3);
  377. + UpdateActionIMSI(conn->lchan->MYSQL_ID, gsms->sender->imsi);
  378. +
  379. LOGP(DSMS, LOGL_INFO, "RX SMS: Sender: %s, MTI: 0x%02x, VPF: 0x%02x, "
  380. "MR: 0x%02x PID: 0x%02x, DCS: 0x%02x, DA: %s, "
  381. "UserDataLength: 0x%02x, UserData: \"%s\"\n",
  382. @@ -1097,6 +1101,10 @@
  383.  
  384. DEBUGP(DSMS, "TX: SMS DELIVER\n");
  385.  
  386. +#warning NICK
  387. + UpdateActionID(conn->lchan->MYSQL_ID, 3);
  388. + UpdateActionIMSI(conn->lchan->MYSQL_ID, conn->subscr->imsi);
  389. +
  390. counter_inc(conn->bts->network->stats.sms.delivered);
  391.  
  392. return gsm411_rp_sendmsg(msg, trans, GSM411_MT_RP_DATA_MT, msg_ref);
  393. diff -u --recursive --new-file 1/src/handover_logic.c 2/src/handover_logic.c
  394. --- 1/src/handover_logic.c 2010-08-17 11:59:24.000000000 +0200
  395. +++ 2/src/handover_logic.c 2010-09-13 11:43:59.544908000 +0200
  396. @@ -128,6 +128,9 @@
  397. new_lchan->rsl_cmode = old_lchan->rsl_cmode;
  398. new_lchan->tch_mode = old_lchan->tch_mode;
  399.  
  400. +#warning NICK
  401. + new_lchan->MYSQL_ID = old_lchan->MYSQL_ID;
  402. +
  403. new_lchan->conn = old_lchan->conn;
  404. new_lchan->conn->ho_lchan = new_lchan;
  405.  
  406. @@ -257,6 +260,9 @@
  407. ho->old_lchan->ts->trx->bts->nr, new_lchan->ts->trx->bts->nr,
  408. ho->old_lchan->ts->trx->arfcn, new_lchan->ts->trx->arfcn);
  409.  
  410. +#warning NICK
  411. + insertUsedBTS(new_lchan->MYSQL_ID, new_lchan->ts->trx->bts->cell_identity, "Handover complete");
  412. +
  413. counter_inc(net->stats.handover.completed);
  414.  
  415. bsc_del_timer(&ho->T3103);
  416. diff -u --recursive --new-file 1/src/Makefile.am 2/src/Makefile.am
  417. --- 1/src/Makefile.am 2010-08-17 11:59:24.000000000 +0200
  418. +++ 2/src/Makefile.am 2010-09-13 12:58:05.929203165 +0200
  419. @@ -25,7 +25,7 @@
  420. rtp_proxy.c bts_siemens_bs11.c bts_ipaccess_nanobts.c \
  421. bts_unknown.c bsc_version.c bsc_api.c bsc_vty.c meas_rep.c
  422.  
  423. -libmsc_a_SOURCES = gsm_subscriber.c db.c \
  424. +libmsc_a_SOURCES = gsm_subscriber.c db.c dbLogging.c \
  425. mncc.c gsm_04_08.c gsm_04_11.c transaction.c \
  426. token_auth.c rrlp.c gsm_04_80.c ussd.c silent_call.c \
  427. handover_decision.c auth.c \
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement