libosmogsm  0.12.0.55-9540
Osmocom GSM library
oap_client.h
Go to the documentation of this file.
1 /* Osmocom Authentication Protocol API */
2 
3 /* (C) 2015 by Sysmocom s.f.m.c. GmbH
4  * All Rights Reserved
5  *
6  * Author: Neels Hofmeyr
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #pragma once
24 
25 #include <stdint.h>
26 
27 struct msgb;
28 struct osmo_oap_message;
29 
30 /* This is the config part for vty. It is essentially copied in
31  * oap_client_state, where values are copied over once the config is
32  * considered valid. */
34  uint16_t client_id;
36  uint8_t secret_k[16];
38  uint8_t secret_opc[16];
39 };
40 
41 /* The runtime state of the OAP client. client_id and the secrets are in fact
42  * duplicated from oap_client_config, so that a separate validation of the
43  * config data is possible, and so that only a struct oap_client_state* is
44  * passed around. */
46  enum {
47  OSMO_OAP_UNINITIALIZED = 0, /* just allocated. */
48  OSMO_OAP_DISABLED, /* disabled by config. */
49  OSMO_OAP_INITIALIZED, /* enabled, config is valid. */
52  OSMO_OAP_REGISTERED
53  } state;
54  uint16_t client_id;
55  uint8_t secret_k[16];
56  uint8_t secret_opc[16];
58 };
59 
60 /* From config, initialize state. Return 0 on success. */
62  struct osmo_oap_client_state *state);
63 
64 /* Construct an OAP registration message and return in *msg_tx. Use
65  * state->client_id and update state->state.
66  * Return 0 on success, or a negative value on error.
67  * If an error is returned, *msg_tx is guaranteed to be NULL. */
68 int osmo_oap_client_register(struct osmo_oap_client_state *state, struct msgb **msg_tx);
69 
70 /* Decode and act on a received OAP message msg_rx. Update state->state. If a
71  * non-NULL pointer is returned in *msg_tx, that msgb should be sent to the OAP
72  * server (and freed) by the caller. The received msg_rx is not freed.
73  * Return 0 on success, or a negative value on error.
74  * If an error is returned, *msg_tx is guaranteed to be NULL. */
76  const struct msgb *msg_rx, struct msgb **msg_tx);
77 
78 /* Allocate a msgb and in it, return the encoded oap_client_msg. Return
79  * NULL on error. (Like oap_client_encode(), but also allocates a msgb.)
80  * About the name: the idea is do_something(oap_client_encoded(my_struct))
81  */
82 struct msgb *osmo_oap_client_encoded(const struct osmo_oap_message *oap_client_msg);
int osmo_oap_client_init(struct osmo_oap_client_config *config, struct osmo_oap_client_state *state)
Definition: oap_client.c:33
uint8_t secret_k[16]
Definition: oap_client.h:36
Definition: oap_client.h:33
int osmo_oap_client_register(struct osmo_oap_client_state *state, struct msgb **msg_tx)
Definition: oap_client.c:151
Definition: oap_client.h:45
uint16_t client_id
Definition: oap_client.h:34
uint16_t client_id
Definition: oap_client.h:54
Definition: oap_client.h:48
int secret_k_present
Definition: oap_client.h:35
int osmo_oap_client_handle(struct osmo_oap_client_state *state, const struct msgb *msg_rx, struct msgb **msg_tx)
Definition: oap_client.c:211
struct msgb * osmo_oap_client_encoded(const struct osmo_oap_message *oap_client_msg)
Definition: oap_client.c:127
int registration_failures
Definition: oap_client.h:57
int secret_opc_present
Definition: oap_client.h:37
uint8_t secret_opc[16]
Definition: oap_client.h:38
Parsed/decoded OAP protocol message.
Definition: oap.h:65