summaryrefslogtreecommitdiffstats
path: root/src/shared/libosmocore/src
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/libosmocore/src')
-rw-r--r--src/shared/libosmocore/src/gsm/a5.c8
-rw-r--r--src/shared/libosmocore/src/gsm/auth_milenage.c15
-rw-r--r--src/shared/libosmocore/src/gsm/lapd_core.c3
-rw-r--r--src/shared/libosmocore/src/gsm/milenage/milenage.c15
-rw-r--r--src/shared/libosmocore/src/gsm/milenage/milenage.h2
-rw-r--r--src/shared/libosmocore/src/vty/command.c176
6 files changed, 165 insertions, 54 deletions
diff --git a/src/shared/libosmocore/src/gsm/a5.c b/src/shared/libosmocore/src/gsm/a5.c
index e330c759..34f271a8 100644
--- a/src/shared/libosmocore/src/gsm/a5.c
+++ b/src/shared/libosmocore/src/gsm/a5.c
@@ -89,10 +89,10 @@ osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul)
#define A5_R3_MASK ((1<<A5_R3_LEN)-1)
#define A5_R4_MASK ((1<<A5_R4_LEN)-1)
-#define A5_R1_TAPS 0x072000 /* x^19 + x^5 + x^2 + x + 1 */
-#define A5_R2_TAPS 0x300000 /* x^22 + x + 1 */
-#define A5_R3_TAPS 0x700080 /* x^23 + x^15 + x^2 + x + 1 */
-#define A5_R4_TAPS 0x010800 /* x^17 + x^5 + 1 */
+#define A5_R1_TAPS 0x072000 /* x^19 + x^18 + x^17 + x^14 + 1 */
+#define A5_R2_TAPS 0x300000 /* x^22 + x^21 + 1 */
+#define A5_R3_TAPS 0x700080 /* x^23 + x^22 + x^21 + x^8 + 1 */
+#define A5_R4_TAPS 0x010800 /* x^17 + x^12 + 1 */
/*! \brief Computes parity of a 32-bit word
* \param[in] x 32 bit word
diff --git a/src/shared/libosmocore/src/gsm/auth_milenage.c b/src/shared/libosmocore/src/gsm/auth_milenage.c
index 2a9ba334..5b2787dd 100644
--- a/src/shared/libosmocore/src/gsm/auth_milenage.c
+++ b/src/shared/libosmocore/src/gsm/auth_milenage.c
@@ -83,10 +83,21 @@ static int milenage_gen_vec_auts(struct osmo_auth_vector *vec,
const uint8_t *_rand)
{
uint8_t sqn_out[6];
+ uint8_t gen_opc[16];
+ uint8_t *opc;
int rc;
- rc = milenage_auts(aud->u.umts.opc, aud->u.umts.k,
- rand_auts, auts, sqn_out);
+ /* Check if we only know OP and compute OPC if required */
+ if (aud->type == OSMO_AUTH_TYPE_UMTS && aud->u.umts.opc_is_op) {
+ rc = milenage_opc_gen(gen_opc, aud->u.umts.k,
+ aud->u.umts.opc);
+ if (rc < 0)
+ return rc;
+ opc = gen_opc;
+ } else
+ opc = aud->u.umts.opc;
+
+ rc = milenage_auts(opc, aud->u.umts.k, rand_auts, auts, sqn_out);
if (rc < 0)
return rc;
diff --git a/src/shared/libosmocore/src/gsm/lapd_core.c b/src/shared/libosmocore/src/gsm/lapd_core.c
index fb79a2f0..96099edb 100644
--- a/src/shared/libosmocore/src/gsm/lapd_core.c
+++ b/src/shared/libosmocore/src/gsm/lapd_core.c
@@ -707,7 +707,7 @@ static void lapd_acknowledge(struct lapd_msg_ctx *lctx)
{
struct lapd_datalink *dl = lctx->dl;
uint8_t nr = lctx->n_recv;
- int s = 0, rej = 0, t200_reset = 0, t200_start = 0;
+ int s = 0, rej = 0, t200_reset = 0;
int i, h;
/* supervisory frame ? */
@@ -758,7 +758,6 @@ static void lapd_acknowledge(struct lapd_msg_ctx *lctx)
if (dl->tx_hist[sub_mod(dl->v_send, 1, dl->range_hist)].msg) {
LOGP(DLLAPD, LOGL_INFO, "start T200, due to unacked I "
"frame(s)\n");
- t200_start = 1;
lapd_start_t200(dl);
}
}
diff --git a/src/shared/libosmocore/src/gsm/milenage/milenage.c b/src/shared/libosmocore/src/gsm/milenage/milenage.c
index cc4e95c5..b43f986a 100644
--- a/src/shared/libosmocore/src/gsm/milenage/milenage.c
+++ b/src/shared/libosmocore/src/gsm/milenage/milenage.c
@@ -327,3 +327,18 @@ int milenage_check(const u8 *opc, const u8 *k, const u8 *sqn, const u8 *_rand,
return 0;
}
+
+int milenage_opc_gen(u8 *opc, const u8 *k, const u8 *op)
+{
+ int i;
+
+ /* Encrypt OP using K */
+ if (aes_128_encrypt_block(k, op, opc))
+ return -1;
+
+ /* XOR the resulting Ek(OP) with OP */
+ for (i = 0; i < 16; i++)
+ opc[i] = opc[i] ^ op[i];
+
+ return 0;
+}
diff --git a/src/shared/libosmocore/src/gsm/milenage/milenage.h b/src/shared/libosmocore/src/gsm/milenage/milenage.h
index d5054d6d..a91e946a 100644
--- a/src/shared/libosmocore/src/gsm/milenage/milenage.h
+++ b/src/shared/libosmocore/src/gsm/milenage/milenage.h
@@ -30,4 +30,6 @@ int milenage_f1(const u8 *opc, const u8 *k, const u8 *_rand,
int milenage_f2345(const u8 *opc, const u8 *k, const u8 *_rand,
u8 *res, u8 *ck, u8 *ik, u8 *ak, u8 *akstar);
+int milenage_opc_gen(u8 *opc, const u8 *k, const u8 *op);
+
#endif /* MILENAGE_H */
diff --git a/src/shared/libosmocore/src/vty/command.c b/src/shared/libosmocore/src/vty/command.c
index ab1eacaa..fda2e17f 100644
--- a/src/shared/libosmocore/src/vty/command.c
+++ b/src/shared/libosmocore/src/vty/command.c
@@ -2268,31 +2268,19 @@ gDEFUN(config_list, config_list_cmd, "list", "Print command list\n")
return CMD_SUCCESS;
}
-/* Write current configuration into file. */
-DEFUN(config_write_file,
- config_write_file_cmd,
- "write file",
- "Write running configuration to memory, network, or terminal\n"
- "Write to configuration file\n")
+static int write_config_file(const char *config_file, char **outpath)
{
unsigned int i;
int fd;
struct cmd_node *node;
- char *config_file;
char *config_file_tmp = NULL;
char *config_file_sav = NULL;
struct vty *file_vty;
+ struct stat st;
- /* Check and see if we are operating under vtysh configuration */
- if (host.config == NULL) {
- vty_out(vty, "Can't save to configuration file, using vtysh.%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- /* Get filename. */
- config_file = host.config;
+ *outpath = NULL;
+ /* Check and see if we are operating under vtysh configuration */
config_file_sav =
_talloc_zero(tall_vty_cmd_ctx,
strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1,
@@ -2307,11 +2295,10 @@ DEFUN(config_write_file,
/* Open file to configuration write. */
fd = mkstemp(config_file_tmp);
if (fd < 0) {
- vty_out(vty, "Can't open configuration file %s.%s",
- config_file_tmp, VTY_NEWLINE);
+ *outpath = talloc_strdup(tall_vty_cmd_ctx, config_file_tmp);
talloc_free(config_file_tmp);
talloc_free(config_file_sav);
- return CMD_WARNING;
+ return -1;
}
/* Make vty for configuration file. */
@@ -2334,38 +2321,37 @@ DEFUN(config_write_file,
if (unlink(config_file_sav) != 0)
if (errno != ENOENT) {
- vty_out(vty,
- "Can't unlink backup configuration file %s.%s",
- config_file_sav, VTY_NEWLINE);
+ *outpath = talloc_strdup(tall_vty_cmd_ctx, config_file_sav);
talloc_free(config_file_sav);
talloc_free(config_file_tmp);
unlink(config_file_tmp);
- return CMD_WARNING;
+ return -2;
+ }
+
+ /* Only link the .sav file if the original file exists */
+ if (stat(config_file, &st) == 0) {
+ if (link(config_file, config_file_sav) != 0) {
+ *outpath = talloc_strdup(tall_vty_cmd_ctx, config_file_sav);
+ talloc_free(config_file_sav);
+ talloc_free(config_file_tmp);
+ unlink(config_file_tmp);
+ return -3;
+ }
+ sync();
+ if (unlink(config_file) != 0) {
+ *outpath = talloc_strdup(tall_vty_cmd_ctx, config_file);
+ talloc_free(config_file_sav);
+ talloc_free(config_file_tmp);
+ unlink(config_file_tmp);
+ return -4;
}
- if (link(config_file, config_file_sav) != 0) {
- vty_out(vty, "Can't backup old configuration file %s.%s",
- config_file_sav, VTY_NEWLINE);
- talloc_free(config_file_sav);
- talloc_free(config_file_tmp);
- unlink(config_file_tmp);
- return CMD_WARNING;
- }
- sync();
- if (unlink(config_file) != 0) {
- vty_out(vty, "Can't unlink configuration file %s.%s",
- config_file, VTY_NEWLINE);
- talloc_free(config_file_sav);
- talloc_free(config_file_tmp);
- unlink(config_file_tmp);
- return CMD_WARNING;
}
if (link(config_file_tmp, config_file) != 0) {
- vty_out(vty, "Can't save configuration file %s.%s", config_file,
- VTY_NEWLINE);
+ *outpath = talloc_strdup(tall_vty_cmd_ctx, config_file);
talloc_free(config_file_sav);
talloc_free(config_file_tmp);
unlink(config_file_tmp);
- return CMD_WARNING;
+ return -5;
}
unlink(config_file_tmp);
sync();
@@ -2374,13 +2360,70 @@ DEFUN(config_write_file,
talloc_free(config_file_tmp);
if (chmod(config_file, 0666 & ~CONFIGFILE_MASK) != 0) {
- vty_out(vty, "Can't chmod configuration file %s: %s (%d).%s",
- config_file, strerror(errno), errno, VTY_NEWLINE);
+ *outpath = talloc_strdup(tall_vty_cmd_ctx, config_file);
+ return -6;
+ }
+
+ return 0;
+}
+
+
+/* Write current configuration into file. */
+DEFUN(config_write_file,
+ config_write_file_cmd,
+ "write file",
+ "Write running configuration to memory, network, or terminal\n"
+ "Write to configuration file\n")
+{
+ char *failed_file;
+ int rc;
+
+ if (host.config == NULL) {
+ vty_out(vty, "Can't save to configuration file, using vtysh.%s",
+ VTY_NEWLINE);
return CMD_WARNING;
}
- vty_out(vty, "Configuration saved to %s%s", config_file, VTY_NEWLINE);
- return CMD_SUCCESS;
+ rc = write_config_file(host.config, &failed_file);
+ switch (rc) {
+ case -1:
+ vty_out(vty, "Can't open configuration file %s.%s",
+ failed_file, VTY_NEWLINE);
+ rc = CMD_WARNING;
+ break;
+ case -2:
+ vty_out(vty, "Can't unlink backup configuration file %s.%s",
+ failed_file, VTY_NEWLINE);
+ rc = CMD_WARNING;
+ break;
+ case -3:
+ vty_out(vty, "Can't backup old configuration file %s.%s",
+ failed_file, VTY_NEWLINE);
+ rc = CMD_WARNING;
+ break;
+ case -4:
+ vty_out(vty, "Can't unlink configuration file %s.%s",
+ failed_file, VTY_NEWLINE);
+ rc = CMD_WARNING;
+ break;
+ case -5:
+ vty_out(vty, "Can't save configuration file %s.%s", failed_file,
+ VTY_NEWLINE);
+ rc = CMD_WARNING;
+ break;
+ case -6:
+ vty_out(vty, "Can't chmod configuration file %s: %s (%d).%s",
+ failed_file, strerror(errno), errno, VTY_NEWLINE);
+ rc = CMD_WARNING;
+ break;
+ default:
+ vty_out(vty, "Configuration saved to %s%s", host.config, VTY_NEWLINE);
+ rc = CMD_SUCCESS;
+ break;
+ }
+
+ talloc_free(failed_file);
+ return rc;
}
ALIAS(config_write_file,
@@ -3160,6 +3203,47 @@ void install_default(enum node_type node)
install_element(node, &show_running_config_cmd);
}
+/**
+ * \brief Write the current running config to a given file
+ * \param[in] vty the vty of the code
+ * \param[in] filename where to store the file
+ * \return 0 in case of success.
+ *
+ * If the filename already exists create a filename.sav
+ * version with the current code.
+ *
+ */
+int osmo_vty_write_config_file(const char *filename)
+{
+ char *failed_file;
+ int rc;
+
+ rc = write_config_file(filename, &failed_file);
+ talloc_free(failed_file);
+ return rc;
+}
+
+/**
+ * \brief Save the current state to the config file
+ * \return 0 in case of success.
+ *
+ * If the filename already exists create a filename.sav
+ * version with the current code.
+ *
+ */
+int osmo_vty_save_config_file(void)
+{
+ char *failed_file;
+ int rc;
+
+ if (host.config == NULL)
+ return -7;
+
+ rc = write_config_file(host.config, &failed_file);
+ talloc_free(failed_file);
+ return rc;
+}
+
/* Initialize command interface. Install basic nodes and commands. */
void cmd_init(int terminal)
{