blob: a939b0d638975b7af6dd03cd9ba889a058e34042 [file] [log] [blame]
Jan Luebbefaaa49c2008-12-27 01:07:07 +00001/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
Holger Freyther12aa50d2009-01-01 18:02:05 +00002 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Jan Luebbefaaa49c2008-12-27 01:07:07 +00003 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01006 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
Jan Luebbefaaa49c2008-12-27 01:07:07 +00008 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010013 * GNU Affero General Public License for more details.
Jan Luebbefaaa49c2008-12-27 01:07:07 +000014 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Jan Luebbefaaa49c2008-12-27 01:07:07 +000017 *
18 */
19
20#ifndef _DB_H
21#define _DB_H
22
Jan Luebbe5c15c852008-12-27 15:59:25 +000023#include <sys/types.h>
Jan Luebbefaaa49c2008-12-27 01:07:07 +000024
Holger Hans Peter Freyther28dcbc52010-12-22 18:21:14 +010025struct gsm_equipment;
26struct gsm_network;
27struct gsm_auth_info;
28struct gsm_auth_tuple;
29struct gsm_sms;
30struct gsm_subscriber;
31
32enum gsm_subscriber_field;
Jan Luebbefaaa49c2008-12-27 01:07:07 +000033
Holger Freyther12aa50d2009-01-01 18:02:05 +000034/* one time initialisation */
Holger Freytherc7b86f92009-06-06 13:54:20 +000035int db_init(const char *name);
Jan Luebbefaaa49c2008-12-27 01:07:07 +000036int db_prepare();
37int db_fini();
38
Holger Freyther12aa50d2009-01-01 18:02:05 +000039/* subscriber management */
Holger Hans Peter Freyther76c64162010-10-04 23:28:28 +080040struct gsm_subscriber *db_create_subscriber(struct gsm_network *net,
Harald Welte9176bd42009-07-23 18:46:00 +020041 char *imsi);
Holger Hans Peter Freyther76c64162010-10-04 23:28:28 +080042struct gsm_subscriber *db_get_subscriber(struct gsm_network *net,
Harald Welte9176bd42009-07-23 18:46:00 +020043 enum gsm_subscriber_field field,
44 const char *subscr);
Holger Hans Peter Freyther76c64162010-10-04 23:28:28 +080045int db_sync_subscriber(struct gsm_subscriber *subscriber);
46int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber);
47int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber);
48int db_subscriber_alloc_token(struct gsm_subscriber *subscriber, u_int32_t* token);
49int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char *imei);
Holger Hans Peter Freyther34e97492009-08-10 07:54:02 +020050int db_sync_equipment(struct gsm_equipment *equip);
Holger Hans Peter Freytherabd0cac2010-12-22 18:12:11 +010051int db_subscriber_update(struct gsm_subscriber *subscriber);
Jan Luebbefaaa49c2008-12-27 01:07:07 +000052
Sylvain Munautc5f488b2009-12-27 19:25:22 +010053/* auth info */
Sylvain Munaut92b2ff52010-06-09 11:32:51 +020054int db_get_authinfo_for_subscr(struct gsm_auth_info *ainfo,
55 struct gsm_subscriber *subscr);
56int db_sync_authinfo_for_subscr(struct gsm_auth_info *ainfo,
Sylvain Munautc614a6a2010-06-09 13:03:39 +020057 struct gsm_subscriber *subscr);
Sylvain Munaut92b2ff52010-06-09 11:32:51 +020058int db_get_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
59 struct gsm_subscriber *subscr);
60int db_sync_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
61 struct gsm_subscriber *subscr);
Sylvain Munautc5f488b2009-12-27 19:25:22 +010062
Harald Welte7e310b12009-03-30 20:56:32 +000063/* SMS store-and-forward */
64int db_sms_store(struct gsm_sms *sms);
Holger Hans Peter Freyther812dad02010-12-24 23:18:31 +010065struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id);
Holger Hans Peter Freytherb464fb42010-03-25 09:59:30 +010066struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, unsigned long long min_id);
Holger Hans Peter Freyther73b878a2010-12-25 00:33:40 +010067struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net, unsigned long long min_subscr_id, unsigned int failed);
Harald Welte2ebabca2009-08-09 19:05:21 +020068struct gsm_sms *db_sms_get_unsent_for_subscr(struct gsm_subscriber *subscr);
Harald Welte7e310b12009-03-30 20:56:32 +000069int db_sms_mark_sent(struct gsm_sms *sms);
Holger Hans Peter Freyther212e1052010-09-17 00:35:46 +080070int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
Harald Welte (local)026531e2009-08-16 10:40:10 +020071
72/* APDU blob storage */
73int db_apdu_blob_store(struct gsm_subscriber *subscr,
74 u_int8_t apdu_id_flags, u_int8_t len,
75 u_int8_t *apdu);
Harald Welteffa55a42009-12-22 19:07:32 +010076
77/* Statistics counter storage */
Harald Weltef2b4cd72010-05-13 11:45:07 +020078struct counter;
Harald Welteffa55a42009-12-22 19:07:32 +010079int db_store_counter(struct counter *ctr);
Harald Weltef2b4cd72010-05-13 11:45:07 +020080struct rate_ctr_group;
81int db_store_rate_ctr_group(struct rate_ctr_group *ctrg);
Harald Welteffa55a42009-12-22 19:07:32 +010082
Jan Luebbefaaa49c2008-12-27 01:07:07 +000083#endif /* _DB_H */