Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 1 | /* (C) 2015-2023 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * 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 |
| 8 | * (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 Affero General Public License for more details. |
| 14 | * |
| 15 | * 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/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <string.h> |
Neels Hofmeyr | ee392bb | 2017-03-16 05:20:50 +0100 | [diff] [blame] | 21 | #include <inttypes.h> |
Neels Hofmeyr | 57a8792 | 2017-10-09 17:51:13 +0200 | [diff] [blame] | 22 | #include <errno.h> |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 23 | |
| 24 | #include <osmocom/core/utils.h> |
| 25 | #include <osmocom/crypt/auth.h> |
| 26 | |
| 27 | #include <sqlite3.h> |
| 28 | |
Neels Hofmeyr | 2f75803 | 2019-11-20 00:37:07 +0100 | [diff] [blame] | 29 | #include <osmocom/hlr/logging.h> |
| 30 | #include <osmocom/hlr/db.h> |
| 31 | #include <osmocom/hlr/auc.h> |
| 32 | #include <osmocom/hlr/rand.h> |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 33 | |
Neels Hofmeyr | 40aa61c | 2017-10-09 17:56:04 +0200 | [diff] [blame] | 34 | #define LOGAUC(imsi, level, fmt, args ...) LOGP(DAUC, level, "IMSI='%s': " fmt, imsi, ## args) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 35 | |
| 36 | /* update the SQN for a given subscriber ID */ |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 37 | int db_update_sqn(struct db_context *dbc, int64_t subscr_id, uint64_t new_sqn) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 38 | { |
Neels Hofmeyr | 4bde949 | 2017-10-06 03:09:34 +0200 | [diff] [blame] | 39 | sqlite3_stmt *stmt = dbc->stmt[DB_STMT_AUC_UPD_SQN]; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 40 | int rc; |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 41 | int ret = 0; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 42 | |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 43 | if (!db_bind_int64(stmt, "$sqn", new_sqn)) |
| 44 | return -EIO; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 45 | |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 46 | if (!db_bind_int64(stmt, "$subscriber_id", subscr_id)) |
| 47 | return -EIO; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 48 | |
| 49 | /* execute the statement */ |
| 50 | rc = sqlite3_step(stmt); |
| 51 | if (rc != SQLITE_DONE) { |
Stefan Sperling | 705b61b | 2018-12-07 12:44:50 +0100 | [diff] [blame] | 52 | LOGP(DAUC, LOGL_ERROR, "Cannot update SQN for subscriber ID=%" PRId64 |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 53 | ": SQL error: (%d) %s\n", |
| 54 | subscr_id, rc, sqlite3_errmsg(dbc->db)); |
| 55 | ret = -EIO; |
| 56 | goto out; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 59 | /* verify execution result */ |
| 60 | rc = sqlite3_changes(dbc->db); |
| 61 | if (!rc) { |
Stefan Sperling | 705b61b | 2018-12-07 12:44:50 +0100 | [diff] [blame] | 62 | LOGP(DAUC, LOGL_ERROR, "Cannot update SQN for subscriber ID=%" PRId64 |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 63 | ": no auc_3g entry for such subscriber\n", subscr_id); |
| 64 | ret = -ENOENT; |
| 65 | } else if (rc != 1) { |
Stefan Sperling | 705b61b | 2018-12-07 12:44:50 +0100 | [diff] [blame] | 66 | LOGP(DAUC, LOGL_ERROR, "Update SQN for subscriber ID=%" PRId64 |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 67 | ": SQL modified %d rows (expected 1)\n", subscr_id, rc); |
| 68 | ret = -EIO; |
| 69 | } |
| 70 | |
| 71 | out: |
Neels Hofmeyr | 76328e5 | 2017-10-09 22:49:25 +0200 | [diff] [blame] | 72 | db_remove_reset(stmt); |
Neels Hofmeyr | 1cbdb70 | 2017-10-09 23:03:57 +0200 | [diff] [blame] | 73 | return ret; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 74 | } |
| 75 | |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 76 | /* hexparse a specific column of a sqlite prepared statement into dst (with length check) |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 77 | * returns byte length in case of success, -EIO on error */ |
| 78 | static int hexparse_stmt(uint8_t *dst, size_t dst_len_min, size_t dst_len_max, sqlite3_stmt *stmt, |
| 79 | int col, const char *col_name, const char *imsi) |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 80 | { |
| 81 | const uint8_t *text; |
| 82 | size_t col_len; |
| 83 | |
| 84 | /* Bytes are stored as hex strings in database, hence divide length by two */ |
| 85 | col_len = sqlite3_column_bytes(stmt, col) / 2; |
| 86 | |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 87 | if (col_len < dst_len_min) { |
| 88 | LOGAUC(imsi, LOGL_ERROR, "Error reading %s, expected min length %lu but has length %lu\n", col_name, |
| 89 | dst_len_min, col_len); |
| 90 | return -EIO; |
| 91 | } |
| 92 | |
| 93 | if (col_len > dst_len_max) { |
| 94 | LOGAUC(imsi, LOGL_ERROR, "Error reading %s, expected max length %lu but has length %lu\n", col_name, |
| 95 | dst_len_max, col_len); |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 96 | return -EIO; |
| 97 | } |
| 98 | |
| 99 | text = sqlite3_column_text(stmt, col); |
| 100 | if (!text) { |
| 101 | LOGAUC(imsi, LOGL_ERROR, "Error reading %s\n", col_name); |
| 102 | return -EIO; |
| 103 | } |
Vadim Yanitskiy | 6156950 | 2022-06-28 17:55:42 +0700 | [diff] [blame] | 104 | |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 105 | if (osmo_hexparse((void *)text, dst, dst_len_max) != col_len) |
Vadim Yanitskiy | 6156950 | 2022-06-28 17:55:42 +0700 | [diff] [blame] | 106 | return -EINVAL; |
| 107 | |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 108 | return col_len; |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 111 | /* obtain the authentication data for a given imsi |
Neels Hofmeyr | bd1dca0 | 2017-11-23 15:25:30 +0100 | [diff] [blame] | 112 | * returns 0 for success, negative value on error: |
| 113 | * -ENOENT if the IMSI is not known, -ENOKEY if the IMSI is known but has no auth data, |
| 114 | * -EIO on db failure */ |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 115 | int db_get_auth_data(struct db_context *dbc, const char *imsi, |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 116 | struct osmo_sub_auth_data2 *aud2g, |
| 117 | struct osmo_sub_auth_data2 *aud3g, |
Neels Hofmeyr | 32633e2 | 2017-10-06 04:26:21 +0200 | [diff] [blame] | 118 | int64_t *subscr_id) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 119 | { |
Neels Hofmeyr | 4bde949 | 2017-10-06 03:09:34 +0200 | [diff] [blame] | 120 | sqlite3_stmt *stmt = dbc->stmt[DB_STMT_AUC_BY_IMSI]; |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 121 | int ret = 0; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 122 | int rc; |
| 123 | |
| 124 | memset(aud2g, 0, sizeof(*aud2g)); |
| 125 | memset(aud3g, 0, sizeof(*aud3g)); |
| 126 | |
Neels Hofmeyr | c5122f2 | 2017-10-09 23:12:57 +0200 | [diff] [blame] | 127 | if (!db_bind_text(stmt, "$imsi", imsi)) |
| 128 | return -EIO; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 129 | |
| 130 | /* execute the statement */ |
| 131 | rc = sqlite3_step(stmt); |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 132 | if (rc == SQLITE_DONE) { |
Neels Hofmeyr | 40aa61c | 2017-10-09 17:56:04 +0200 | [diff] [blame] | 133 | LOGAUC(imsi, LOGL_INFO, "No such subscriber\n"); |
Neels Hofmeyr | 57a8792 | 2017-10-09 17:51:13 +0200 | [diff] [blame] | 134 | ret = -ENOENT; |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 135 | goto out; |
| 136 | } else if (rc != SQLITE_ROW) { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 137 | LOGAUC(imsi, LOGL_ERROR, "Error executing SQL: %d\n", rc); |
Neels Hofmeyr | 57a8792 | 2017-10-09 17:51:13 +0200 | [diff] [blame] | 138 | ret = -EIO; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 139 | goto out; |
| 140 | } |
| 141 | |
| 142 | /* as an optimization, we retrieve the subscriber ID, to ensure we can |
| 143 | * update the SQN later without having to go back via a JOIN with the |
| 144 | * subscriber table. */ |
| 145 | if (subscr_id) |
| 146 | *subscr_id = sqlite3_column_int64(stmt, 0); |
| 147 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 148 | /* obtain result values using sqlite3_column_*() */ |
| 149 | if (sqlite3_column_type(stmt, 1) == SQLITE_INTEGER) { |
| 150 | /* we do have some 2G authentication data */ |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 151 | if (hexparse_stmt(aud2g->u.gsm.ki, sizeof(aud2g->u.gsm.ki), sizeof(aud2g->u.gsm.ki), |
| 152 | stmt, 2, "Ki", imsi) < 0) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 153 | goto end_2g; |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 154 | aud2g->algo = sqlite3_column_int(stmt, 1); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 155 | aud2g->type = OSMO_AUTH_TYPE_GSM; |
| 156 | } else |
| 157 | LOGAUC(imsi, LOGL_DEBUG, "No 2G Auth Data\n"); |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 158 | end_2g: |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 159 | if (sqlite3_column_type(stmt, 3) == SQLITE_INTEGER) { |
| 160 | /* we do have some 3G authentication data */ |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 161 | rc = hexparse_stmt(aud3g->u.umts.k, 16, sizeof(aud3g->u.umts.k), stmt, 4, "K", imsi); |
| 162 | if (rc < 0) { |
Neels Hofmeyr | 57a8792 | 2017-10-09 17:51:13 +0200 | [diff] [blame] | 163 | ret = -EIO; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 164 | goto out; |
| 165 | } |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 166 | aud3g->u.umts.k_len = rc; |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 167 | aud3g->algo = sqlite3_column_int(stmt, 3); |
| 168 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 169 | /* UMTS Subscribers can have either OP or OPC */ |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 170 | if (sqlite3_column_text(stmt, 5)) { |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 171 | rc = hexparse_stmt(aud3g->u.umts.opc, 16, sizeof(aud3g->u.umts.opc), stmt, 5, "OP", imsi); |
| 172 | if (rc < 0) { |
Neels Hofmeyr | 57a8792 | 2017-10-09 17:51:13 +0200 | [diff] [blame] | 173 | ret = -EIO; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 174 | goto out; |
| 175 | } |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 176 | aud3g->u.umts.opc_len = rc; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 177 | aud3g->u.umts.opc_is_op = 1; |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 178 | } else { |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 179 | rc = hexparse_stmt(aud3g->u.umts.opc, 16, sizeof(aud3g->u.umts.opc), stmt, 6, "OPC", imsi); |
| 180 | if (rc < 0) { |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 181 | ret = -EIO; |
| 182 | goto out; |
| 183 | } |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 184 | aud3g->u.umts.opc_len = rc; |
Oliver Smith | 6401b90 | 2019-07-24 11:32:45 +0200 | [diff] [blame] | 185 | aud3g->u.umts.opc_is_op = 0; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 186 | } |
| 187 | aud3g->u.umts.sqn = sqlite3_column_int64(stmt, 7); |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 188 | aud3g->u.umts.ind_bitlen = sqlite3_column_int(stmt, 8); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 189 | /* FIXME: amf? */ |
| 190 | aud3g->type = OSMO_AUTH_TYPE_UMTS; |
| 191 | } else |
| 192 | LOGAUC(imsi, LOGL_DEBUG, "No 3G Auth Data\n"); |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 193 | |
| 194 | if (aud2g->type == 0 && aud3g->type == 0) |
Neels Hofmeyr | bd1dca0 | 2017-11-23 15:25:30 +0100 | [diff] [blame] | 195 | ret = -ENOKEY; |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 196 | |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 197 | out: |
Neels Hofmeyr | 76328e5 | 2017-10-09 22:49:25 +0200 | [diff] [blame] | 198 | db_remove_reset(stmt); |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 199 | return ret; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Neels Hofmeyr | bd1dca0 | 2017-11-23 15:25:30 +0100 | [diff] [blame] | 202 | /* return number of vectors generated, negative value on error: |
| 203 | * -ENOENT if the IMSI is not known, -ENOKEY if the IMSI is known but has no auth data, |
| 204 | * -EIO on db failure */ |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 205 | int db_get_auc(struct db_context *dbc, const char *imsi, |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 206 | unsigned int auc_3g_ind, struct osmo_auth_vector *vec, |
| 207 | unsigned int num_vec, const uint8_t *rand_auts, |
Harald Welte | 06f5af2 | 2019-08-21 20:01:31 +0200 | [diff] [blame] | 208 | const uint8_t *auts, bool separation_bit) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 209 | { |
Harald Welte | a854b48 | 2023-05-30 17:27:32 +0200 | [diff] [blame] | 210 | struct osmo_sub_auth_data2 aud2g, aud3g; |
Neels Hofmeyr | 32633e2 | 2017-10-06 04:26:21 +0200 | [diff] [blame] | 211 | int64_t subscr_id; |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 212 | int ret = 0; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 213 | int rc; |
| 214 | |
| 215 | rc = db_get_auth_data(dbc, imsi, &aud2g, &aud3g, &subscr_id); |
Neels Hofmeyr | 57a8792 | 2017-10-09 17:51:13 +0200 | [diff] [blame] | 216 | if (rc) |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 217 | return rc; |
| 218 | |
Neels Hofmeyr | a450a85 | 2019-12-12 17:06:22 +0100 | [diff] [blame] | 219 | /* modulo by the IND bitlen value range. For example, ind_bitlen == 5 would modulo 32: |
| 220 | * 1 << 5 == 0b0100000 == 32 |
| 221 | * - 1 == 0b0011111 == bitmask of 5 lowest bits |
| 222 | * x &= 0b0011111 == modulo 32 |
| 223 | * Why do this? osmo-hlr cannot possibly choose individual VLR INDs always matching all subscribers' IND_bitlen, |
| 224 | * which might vary wildly. Instead, let hlr.c pass in an arbitrarily high number here, and the modulo does a |
| 225 | * round-robin if the IND pools that this subscriber has available. */ |
| 226 | auc_3g_ind &= (1U << aud3g.u.umts.ind_bitlen) - 1; |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 227 | aud3g.u.umts.ind = auc_3g_ind; |
Neels Hofmeyr | a450a85 | 2019-12-12 17:06:22 +0100 | [diff] [blame] | 228 | |
Harald Welte | 06f5af2 | 2019-08-21 20:01:31 +0200 | [diff] [blame] | 229 | /* the first bit (bit0) cannot be used as AMF anymore, but has been |
| 230 | * re-appropriated as the separation bit. See 3GPP TS 33.102 Annex H |
| 231 | * together with 3GPP TS 33.401 / 33.402 / 33.501 */ |
| 232 | aud3g.u.umts.amf[0] = aud3g.u.umts.amf[0] & 0x7f; |
| 233 | if (separation_bit) |
| 234 | aud3g.u.umts.amf[0] |= 0x80; |
Neels Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 235 | |
Neels Hofmeyr | 0acd31e | 2016-12-16 16:11:36 +0100 | [diff] [blame] | 236 | LOGAUC(imsi, LOGL_DEBUG, "Calling to generate %u vectors\n", num_vec); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 237 | rc = auc_compute_vectors(vec, num_vec, &aud2g, &aud3g, rand_auts, auts); |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 238 | if (rc < 0) { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 239 | num_vec = 0; |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 240 | ret = -1; |
| 241 | } else { |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 242 | num_vec = rc; |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 243 | ret = num_vec; |
| 244 | } |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 245 | LOGAUC(imsi, LOGL_INFO, "Generated %u vectors\n", num_vec); |
| 246 | |
| 247 | /* Update SQN in database, as needed */ |
| 248 | if (aud3g.algo) { |
Neels Hofmeyr | edebc22 | 2017-03-16 04:58:58 +0100 | [diff] [blame] | 249 | LOGAUC(imsi, LOGL_DEBUG, "Updating SQN=%" PRIu64 " in DB\n", |
| 250 | aud3g.u.umts.sqn); |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 251 | rc = db_update_sqn(dbc, subscr_id, aud3g.u.umts.sqn); |
| 252 | /* don't tell caller we generated any triplets in case of |
| 253 | * update error */ |
| 254 | if (rc < 0) { |
| 255 | LOGAUC(imsi, LOGL_ERROR, "Error updating SQN: %d\n", rc); |
| 256 | num_vec = 0; |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 257 | ret = -1; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Harald Welte | cfc752b | 2016-05-05 16:38:14 +0200 | [diff] [blame] | 261 | return ret; |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 262 | } |