aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmsc/db.c
AgeCommit message (Collapse)AuthorFilesLines
2015-04-10nitb: Fix IMSI/IMEI buffer handling (Coverity)Jacob Erlbeck1-2/+2
Currently the handling of the buffers is not done consistently. Some code assumes that the whole buffer may be used to store the string while at other places, the last buffer byte is left untouched in the assumption that it contains a terminating NUL-character. The latter is the correct behaviour. This commit changes to code to not touch the last byte in the buffers and to rely on the last byte being NUL. So the maximum IMSI/IMEI length is GSM_IMSI_LENGTH-1/GSM_IMEI_LENGTH-1. For information: We assume that we allocate the structure with talloc_zero. This means we have NULed the entire imsi array and then only write sizeof - 1 characters to it. So the last byte remains NUL. Fixes: Coverity CID 1206568, 1206567 Sponsored-by: On-Waves ehf
2014-12-05msc: Add and use gsm_subscriber_groupJacob Erlbeck1-2/+2
Currently every subcriber object directly refers to the gsm_network which contains a flag shared by every related subscriber (keep_subscr). This adds a dependency on gsm_network even if only the function defined in gsm_subscriber_base.c are used. This patch adds a new struct gsm_subscriber_group which contains the keep_subscr flag and a back reference to the network object. The latter is not dereferenced in gsm_subscriber_base.c, so it can safely be set to NULL when only that part of the gsm_subscriber API is being used. It also changes that API to use gsm_subscriber_group instead of gsm_network parameters. Since there are some places where a pointer to the gsm_network is needed but where only a gsm_subscriber is available, a 'net' back pointer is added to the group struct, too. Nevertheless subscr group and network could be separated completely, but this is not the topic of this commit. Sponsored-by: On-Waves ehf
2014-08-02DB: produce a backtrace in case of a DB errorHarald Welte1-0/+1
This helps us to identify where exactly in our code the DB error originates from.
2014-07-03db: Use ulonglong to access the database for sqlite3Holger Hans Peter Freyther1-14/+14
The type in the schema is integer but we need to use ulonglong to read it as otherwise the read will fail. DBI: -7: The requested variable type does not match what libdbi thinks it should be
2014-04-30db: Fix fall-out with the subscriber removal in the subscriber deletion codeHolger Hans Peter Freyther1-2/+2
The sender_id is gone so the code that attempted to delete SMS didn't work anymore. Delete the SMS based on src_addr or the dest_addr. Fixes: ====================================================================== ERROR: testSubscriberAddRemove (__main__.TestCtrlNITB) ---------------------------------------------------------------------- Traceback (most recent call last): File "tests/ctrl_test_runner.py", line 379, in testSubscriberAddRemove r = self.do_set('subscriber-delete-v1', '2620345') File "tests/ctrl_test_runner.py", line 114, in do_set return self.recv_msgs()[id] KeyError: 1002
2014-04-30db: Add testcase for the db migration.Holger Hans Peter Freyther1-0/+2
2014-04-30sms: Add code to migrate the database to the new schemaHolger Hans Peter Freyther1-16/+193
This is mostly based on Alexander's migration code. The code adds transaction handling and some sanity checks and cleanups to the code. We made the decision to fork the sms_from_result method and freeze it to that version. This way sms_from_result can move forward without having to deal with legacy.
2014-04-30sms: Do not store received id in the SMS database.Alexander Chemeris1-21/+10
That was a bad idea from the very beginning. A visible result of this is a wrong SMS routing when you change subscriber extensions, while having queued SMS. It's also a very wrong thing from the code layering perspective. I think the next logical step should be to remove "receiver" pointer from the gsm_sms structure into a structure, special for the internal SMS queue.
2014-04-30sms: Kill the sms->sender and use addr/ton/npi throughout the codeHolger Hans Peter Freyther1-25/+37
This is an incompatible database schema change. Store the type of the address in the database for both the sender and the receiver. Currently it is possible to use SMPP to store a SMS and the NPI and TON will be lost on the delivery of the SMS. The schema is changed to make the delivery always use the right NPI/TON. This patch is not ready for the master branch as there is no upgrade path for the HLR yet.
2014-03-23nitb/ctrl: Implement a command to list all active subscribersHolger Hans Peter Freyther1-0/+33
This is only useful for small networks. List the IMSI and MSISDN of all active subscribers. Fixes: SYS#266
2014-03-23nitb/ctrl: Implement creating and deleting subscribersHolger Hans Peter Freyther1-0/+87
Sadly there is no proper foreign key relationship on the tables that related to the Subscriber. This means we can't use a DELETE with Cascade and need to delete everything by hand. To make things worse maybe the SMS/Paging code is still using the subscriber making the operation more dangerous. I had added NULL checks for sender_id/receiver_id at 30C3 so we should not crash in this situation. Fixes: SYS#274
2014-03-09db,sms: Rename db_sms_mark_sent() to db_sms_mark_delivered()Alexander Chemeris1-2/+2
In MT-SMS the message is being delivered. Make the naming follow that. The schema still refers to "sent" while it should be "delivered" too.
2014-03-07db: Remove the german from the log messageAlexander Chemeris1-1/+1
2013-12-27db: Avoid crash we have seen with the dbi code when reading a SMSHolger Hans Peter Freyther1-0/+15
Avoid a crash when reading a SMS and a Subscriber could not be resolved. It is not clear why the read was failing. The sender_id and the receiver_id was valid for the given sms. I assume that the database has been locked due external access to it. The side-effect is that in case of such a failure the sms_queue will start to deliver starting from subscriber id = 0 again. #1 0x0000000000428bec in sms_from_result (net=0x156a270, result=0x15eda30) at db.c:1146 #2 0x000000000042a8e0 in db_sms_get_unsent_by_subscr (net=0x156a270, min_subscr_id=<optimized out>, failed=<optimized out>) at db.c:1255 #3 0x000000000042e900 in take_next_sms (smsq=<optimized out>) at sms_queue.c:193 #4 sms_submit_pending (_data=0x158e300) at sms_queue.c:227 #5 0x00007f3fd30de3bc in osmo_timers_update () at timer.c:243 #6 0x00007f3fd30de69b in osmo_select_main (polling=0) at select.c:133 #7 0x0000000000406fbc in main (argc=9, argv=<optimized out>) at bsc_hack.c:346 (gdb) frame 1 #1 0x0000000000428bec in sms_from_result (net=0x156a270, result=0x15eda30) at db.c:1146 1146 strncpy(sms->src.addr, sms->sender->extension, sizeof(sms->src.addr)-1); (gdb) p *sms (gdb) p sms->sender $1 = (struct gsm_subscriber *) 0x0 (gdb) p sender_id $2 = <optimized out>
2013-12-26db: Fetch the authorized key using ulonglongKevin Redon1-2/+3
Location Update Requests time out and get rejected because the subscriber is not authorized. Authorizing the subscriber through openBSC or sqlite3 doesn't help the subscriber is still seen and shown as not authorized The value is read as uint, this is the wrong type it's a (u)longlong in libdbi 0.9.0 and later.
2013-10-13db: Remove the struct gsm_network from the database layerHolger Hans Peter Freyther1-6/+3
The database code should not know about the network. Move the setting of the network pointer into the subscriber layer.
2013-10-04Fix typo ',' -> ';' at the end of a line.Alexander Chemeris1-1/+1
Funny, this is a correct C expression and doesn't change execution, thus it stayed unnoticed for quite a while.
2013-07-27expiration: Allow to disable the periodic location updating procedureHolger Hans Peter Freyther1-20/+39
Disable the periodic LU using "no periodic location update" VTY command. In that case set the expire_lu to 0 which will then be translated to a NULL in the database layer. This leads to a bit of copy and paste in the db_sync_subscriber method but I don't see how we could easily use 'datetime(%i, 'unixepoch')' and 'NULL' at the same time. Change the query to find expired queries to check for NOT NULL and the time being in the past. This means if there are still old subscribers in the database they might not be expired. One would need to execute a query like "UPATE Subscriber SET expire_lu = 0 WHERE expire_lu is null". The same applies when disabling the periodic LU. One would need to update the database by hand. Manual tests executed/passed: 1.) periodic LU enabled: * use gst LUTest.st to do a LU * UPDATE Subscriber SET expire_lu=datetime('now'); * observe the subscriber being expired (it was) 2.) periodic LU disabled: * use gst LUTest.st to do a LU * verify that the expire_lu is NULL in the database
2013-07-27misc: Fix compilation warningsHolger Hans Peter Freyther1-1/+1
bsc_api.c:417:3: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘unsigned int’ [-Wformat] bsc_api.c: In function ‘handle_ass_fail’: bsc_api.c:458:3: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘unsigned int’ [-Wformat] db.c: In function ‘db_sync_subscriber’: db.c:785:3: warning: format ‘%i’ expects argument of type ‘int’, but argument 8 has type ‘time_t’ [-Wformat] osmo_msc.c: In function ‘msc_release_connection’: osmo_msc.c:145:20: warning: unused variable ‘trans’ [-Wunused-variable] smpp_smsc.c: In function ‘link_accept_cb’: smpp_smsc.c:891:24: warning: assignment from incompatible pointer type [enabled by default] smpp_smsc.c:271:1: warning: ‘esme_by_system_id’ defined but not used [-Wunused-function] smpp_openbsc.c: In function ‘smpp_openbsc_init’: smpp_openbsc.c:545:2: warning: implicit declaration of function ‘smpp_vty_init’ [-Wimplicit-function-declaration] osmo_bsc_ctrl.c: In function ‘verify_bts_loc’: osmo_bsc_ctrl.c:340:19: warning: variable ‘height’ set but not used [-Wunused-but-set-variable smpp_mirror.c: In function ‘main’: smpp_mirror.c:297:2: warning: implicit declaration of function ‘osmo_init_logging’ [-Wimplicit-function-declaration]
2013-07-04db: Fix an issue with the memsetHolger Hans Peter Freyther1-1/+1
We want to memset the entire area of the atuple and not just the first four/eight bytes of the data. Fixes: Coverity CID 1040708
2013-01-01libmsc: Track and update the location update expiryJan Luebbe1-6/+97
Set the subscriber expiry timeout to twice the duration of the location update period and provide functions subscr_expire() and db_subscriber_expire() to mark subscribers offline that have missed two location update periods. This patch increases the DB revision to 3, so the hlr will be incompatible with prior versions. We should allow 0 for T3212 as well to disable the location update period. In that case we will need a way to indicate that in the database.
2012-11-24SMPP: add small utility program 'smpp_mirror'Harald Welte1-3/+4
This program binds as ESME transceiver to a SMSC and simply mirrors back all SMS that it receives.
2012-05-07libmsc/db: Fix max value of ainfo->a3a8_ki_len in db_get_authinfo_for_subscrSylvain Munaut1-1/+1
Thanks to Robert Ingr for pointing this out Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-07-16db: use ANSI (void) function declarationsHarald Welte1-2/+2
2011-07-16db: fix Smatch warningsHarald Welte1-5/+3
/home/laforge/projects/git/openbsc/openbsc/src/libmsc/db.c +254 db_fini(6) info: redundant null check on db_dirname calling free() /home/laforge/projects/git/openbsc/openbsc/src/libmsc/db.c +256 db_fini(8) info: redundant null check on db_basename calling free() /home/laforge/projects/git/openbsc/openbsc/src/libmsc/db.c +280 db_create_subscriber(20) warn: variable dereferenced before check 'subscr'
2011-05-07src: use namespace prefix osmo_* for misc utilsPablo Neira Ayuso1-3/+3
Summary of changes: s/bcd2char/osmo_bcd2char/g s/char2bcd/osmo_char2bcd/g s/hexparse/osmo_hexparse/g s/hexdump/osmo_hexdump/g s/hexdump_nospc/osmo_hexdump_nospc/g s/ubit_dump/osmo_ubit_dump/g s/static_assert/osmo_static_assert/g
2011-05-06src: use namespace prefix osmo_counter*Pablo Neira Ayuso1-1/+1
Summary of changes: s/struct counter/struct osmo_counter/g s/counter_inc/osmo_counter_inc/g s/counter_get/osmo_counter_get/g s/counter_reset/osmo_counter_reset/g s/counter_alloc/osmo_counter_alloc/g s/counter_free/osmo_counter_free
2011-04-18misc: Move from u_int to uint types of stdint.hHolger Hans Peter Freyther1-7/+7
This was done with sed on the files.
2011-03-23src: use new library libosmogsm and new path to headers in libosmocorePablo Neira Ayuso1-3/+3
libosmogsm is a new library that is distributed in the libosmocore. Now, openbsc depends on it. This patch gets openbsc with this change. This patch also rewrites all include path to the new osmocom/[gsm|core] Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-04prefix sub-directories containing libraries with 'lib'Harald Welte1-0/+1303
... and make sure tests work again after restructuring