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 | * @{ |
| 5 | */ |
| 6 | |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 7 | /*! \file prim.h */ |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 8 | |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 9 | #include <stdint.h> |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 10 | #include <osmocom/core/msgb.h> |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 11 | |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 12 | #define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF)) |
| 13 | #define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation) |
| 14 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 15 | /*! \brief primitive operation */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 16 | enum osmo_prim_operation { |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 17 | PRIM_OP_REQUEST, /*!< \brief request */ |
| 18 | PRIM_OP_RESPONSE, /*!< \brief response */ |
| 19 | PRIM_OP_INDICATION, /*!< \brief indication */ |
Neels Hofmeyr | f6d9f37 | 2016-01-18 10:44:15 +0100 | [diff] [blame] | 20 | PRIM_OP_CONFIRM, /*!< \brief confirm */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 21 | }; |
| 22 | |
Harald Welte | c959afd | 2015-12-25 17:14:07 +0100 | [diff] [blame] | 23 | extern const struct value_string osmo_prim_op_names[5]; |
Harald Welte | a2db75f | 2015-12-22 22:11:27 +0100 | [diff] [blame] | 24 | |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 25 | #define _SAP_GSM_SHIFT 24 |
| 26 | |
| 27 | #define _SAP_GSM_BASE (0x01 << _SAP_GSM_SHIFT) |
| 28 | #define _SAP_TETRA_BASE (0x02 << _SAP_GSM_SHIFT) |
Harald Welte | a2db75f | 2015-12-22 22:11:27 +0100 | [diff] [blame] | 29 | #define _SAP_SS7_BASE (0x03 << _SAP_GSM_SHIFT) |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 30 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 31 | /*! \brief primitive header */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 32 | struct osmo_prim_hdr { |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 33 | unsigned int sap; /*!< \brief Service Access Point */ |
| 34 | unsigned int primitive; /*!< \brief Primitive number */ |
| 35 | enum osmo_prim_operation operation; /*! \brief Primitive Operation */ |
| 36 | struct msgb *msg; /*!< \brief \ref msgb containing associated data */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 39 | /*! \brief initialize a primitive header |
| 40 | * \param[in,out] oph primitive header |
| 41 | * \param[in] sap Service Access Point |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 42 | * \param[in] primitive Primitive Number |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 43 | * \param[in] operation Primitive Operation (REQ/RESP/IND/CONF) |
| 44 | * \param[in] msg Message |
| 45 | */ |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 46 | static inline void |
| 47 | osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap, |
| 48 | unsigned int primitive, enum osmo_prim_operation operation, |
| 49 | struct msgb *msg) |
| 50 | { |
| 51 | oph->sap = sap; |
| 52 | oph->primitive = primitive; |
| 53 | oph->operation = operation; |
| 54 | oph->msg = msg; |
| 55 | } |
| 56 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 57 | /*! \brief primitive handler callback type */ |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 58 | typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx); |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 59 | |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 60 | /*! @} */ |