Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 1 | #pragma once |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 2 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 3 | /*! \defgroup prim Osmocom primitives |
| 4 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 5 | * \file prim.h */ |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 6 | |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 8 | #include <osmocom/core/msgb.h> |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 9 | |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 10 | #define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF)) |
| 11 | #define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation) |
| 12 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 13 | /*! primitive operation */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 14 | enum osmo_prim_operation { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 15 | PRIM_OP_REQUEST, /*!< request */ |
| 16 | PRIM_OP_RESPONSE, /*!< response */ |
| 17 | PRIM_OP_INDICATION, /*!< indication */ |
| 18 | PRIM_OP_CONFIRM, /*!< confirm */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 19 | }; |
| 20 | |
Harald Welte | c959afd | 2015-12-25 17:14:07 +0100 | [diff] [blame] | 21 | extern const struct value_string osmo_prim_op_names[5]; |
Harald Welte | a2db75f | 2015-12-22 22:11:27 +0100 | [diff] [blame] | 22 | |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 23 | #define _SAP_GSM_SHIFT 24 |
| 24 | |
| 25 | #define _SAP_GSM_BASE (0x01 << _SAP_GSM_SHIFT) |
| 26 | #define _SAP_TETRA_BASE (0x02 << _SAP_GSM_SHIFT) |
Harald Welte | a2db75f | 2015-12-22 22:11:27 +0100 | [diff] [blame] | 27 | #define _SAP_SS7_BASE (0x03 << _SAP_GSM_SHIFT) |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 28 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 29 | /*! primitive header */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 30 | struct osmo_prim_hdr { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 31 | unsigned int sap; /*!< Service Access Point */ |
| 32 | unsigned int primitive; /*!< Primitive number */ |
| 33 | enum osmo_prim_operation operation; /*! Primitive Operation */ |
| 34 | struct msgb *msg; /*!< \ref msgb containing associated data */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 37 | /*! initialize a primitive header |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 38 | * \param[in,out] oph primitive header |
| 39 | * \param[in] sap Service Access Point |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 40 | * \param[in] primitive Primitive Number |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 41 | * \param[in] operation Primitive Operation (REQ/RESP/IND/CONF) |
| 42 | * \param[in] msg Message |
| 43 | */ |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 44 | static inline void |
| 45 | osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap, |
| 46 | unsigned int primitive, enum osmo_prim_operation operation, |
| 47 | struct msgb *msg) |
| 48 | { |
| 49 | oph->sap = sap; |
| 50 | oph->primitive = primitive; |
| 51 | oph->operation = operation; |
| 52 | oph->msg = msg; |
| 53 | } |
| 54 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 55 | /*! primitive handler callback type */ |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 56 | typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx); |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 57 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 58 | /*! magic value to be used as final record of \ref |
Harald Welte | acd08fe | 2017-04-08 23:35:24 +0200 | [diff] [blame] | 59 | * osmo_prim_event_map */ |
| 60 | #define OSMO_NO_EVENT 0xFFFFFFFF |
| 61 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 62 | /*! single entry in a SAP/PRIM/OP -> EVENT map */ |
Harald Welte | acd08fe | 2017-04-08 23:35:24 +0200 | [diff] [blame] | 63 | struct osmo_prim_event_map { |
| 64 | unsigned int sap; /*!< SAP to match */ |
| 65 | unsigned int primitive; /*!< primtiive to match */ |
| 66 | enum osmo_prim_operation operation; /*!< operation to match */ |
| 67 | uint32_t event; /*!< event as result if above match */ |
| 68 | }; |
| 69 | |
| 70 | uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph, |
| 71 | const struct osmo_prim_event_map *maps); |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 72 | /*! @} */ |