Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 1 | #ifndef OSMO_PRIMITIVE_H |
| 2 | #define OSMO_PRIMITIVE_H |
| 3 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 4 | /*! \defgroup prim Osmocom primitives |
| 5 | * @{ |
| 6 | */ |
| 7 | |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 8 | /*! \file prim.h */ |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 9 | |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 10 | #include <stdint.h> |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 11 | #include <osmocom/core/msgb.h> |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 12 | |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 13 | #define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF)) |
| 14 | #define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation) |
| 15 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 16 | /*! \brief primitive operation */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 17 | enum osmo_prim_operation { |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 18 | PRIM_OP_REQUEST, /*!< \brief request */ |
| 19 | PRIM_OP_RESPONSE, /*!< \brief response */ |
| 20 | PRIM_OP_INDICATION, /*!< \brief indication */ |
| 21 | PRIM_OP_CONFIRM, /*!< \brief cofirm */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 22 | }; |
| 23 | |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 24 | #define _SAP_GSM_SHIFT 24 |
| 25 | |
| 26 | #define _SAP_GSM_BASE (0x01 << _SAP_GSM_SHIFT) |
| 27 | #define _SAP_TETRA_BASE (0x02 << _SAP_GSM_SHIFT) |
| 28 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 29 | /*! \brief primitive header */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 30 | struct osmo_prim_hdr { |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 31 | unsigned int sap; /*!< \brief Service Access Point */ |
| 32 | unsigned int primitive; /*!< \brief Primitive number */ |
| 33 | enum osmo_prim_operation operation; /*! \brief Primitive Operation */ |
| 34 | struct msgb *msg; /*!< \brief \ref msgb containing associated data */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 37 | /*! \brief initialize a primitive header |
| 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 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 55 | /*! \brief 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 | |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 58 | /*! @} */ |
| 59 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 60 | #endif /* OSMO_PRIMITIVE_H */ |