Neels Hofmeyr | d739f09 | 2015-10-12 11:57:34 +0200 | [diff] [blame] | 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; |
Harald Welte | 564c065 | 2016-04-27 18:14:14 +0200 | [diff] [blame^] | 28 | struct osmo_oap_message; |
Neels Hofmeyr | d739f09 | 2015-10-12 11:57:34 +0200 | [diff] [blame] | 29 | |
| 30 | /* This is the config part for vty. It is essentially copied in oap_state, |
| 31 | * where values are copied over once the config is considered valid. */ |
| 32 | struct oap_config { |
| 33 | uint16_t client_id; |
| 34 | int secret_k_present; |
| 35 | uint8_t secret_k[16]; |
| 36 | int secret_opc_present; |
| 37 | uint8_t secret_opc[16]; |
| 38 | }; |
| 39 | |
| 40 | /* The runtime state of the OAP client. client_id and the secrets are in fact |
| 41 | * duplicated from oap_config, so that a separate validation of the config data |
| 42 | * is possible, and so that only a struct oap_state* is passed around. */ |
| 43 | struct oap_state { |
| 44 | enum { |
| 45 | OAP_UNINITIALIZED = 0, /* just allocated. */ |
| 46 | OAP_DISABLED, /* disabled by config. */ |
| 47 | OAP_INITIALIZED, /* enabled, config is valid. */ |
| 48 | OAP_REQUESTED_CHALLENGE, |
| 49 | OAP_SENT_CHALLENGE_RESULT, |
| 50 | OAP_REGISTERED |
| 51 | } state; |
| 52 | uint16_t client_id; |
| 53 | uint8_t secret_k[16]; |
| 54 | uint8_t secret_opc[16]; |
| 55 | int registration_failures; |
| 56 | }; |
| 57 | |
| 58 | /* From config, initialize state. Return 0 on success. */ |
| 59 | int oap_init(struct oap_config *config, struct oap_state *state); |
| 60 | |
| 61 | /* Construct an OAP registration message and return in *msg_tx. Use |
| 62 | * state->client_id and update state->state. |
| 63 | * Return 0 on success, or a negative value on error. |
| 64 | * If an error is returned, *msg_tx is guaranteed to be NULL. */ |
| 65 | int oap_register(struct oap_state *state, struct msgb **msg_tx); |
| 66 | |
| 67 | /* Decode and act on a received OAP message msg_rx. Update state->state. If a |
| 68 | * non-NULL pointer is returned in *msg_tx, that msgb should be sent to the OAP |
| 69 | * server (and freed) by the caller. The received msg_rx is not freed. |
| 70 | * Return 0 on success, or a negative value on error. |
| 71 | * If an error is returned, *msg_tx is guaranteed to be NULL. */ |
| 72 | int oap_handle(struct oap_state *state, const struct msgb *msg_rx, struct msgb **msg_tx); |
| 73 | |
| 74 | /* Allocate a msgb and in it, return the encoded oap_msg. Return NULL on |
| 75 | * error. (Like oap_encode(), but also allocates a msgb.) |
| 76 | * About the name: the idea is do_something(oap_encoded(my_struct)) */ |
Harald Welte | 564c065 | 2016-04-27 18:14:14 +0200 | [diff] [blame^] | 77 | struct msgb *oap_encoded(const struct osmo_oap_message *oap_msg); |
Neels Hofmeyr | d739f09 | 2015-10-12 11:57:34 +0200 | [diff] [blame] | 78 | |