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 | |
| 8 | /*! \file prim.c */ |
| 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 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 13 | /*! \brief primitive operation */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 14 | enum osmo_prim_operation { |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 15 | PRIM_OP_REQUEST, /*!< \brief request */ |
| 16 | PRIM_OP_RESPONSE, /*!< \brief response */ |
| 17 | PRIM_OP_INDICATION, /*!< \brief indication */ |
| 18 | PRIM_OP_CONFIRM, /*!< \brief cofirm */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 19 | }; |
| 20 | |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 21 | #define _SAP_GSM_SHIFT 24 |
| 22 | |
| 23 | #define _SAP_GSM_BASE (0x01 << _SAP_GSM_SHIFT) |
| 24 | #define _SAP_TETRA_BASE (0x02 << _SAP_GSM_SHIFT) |
| 25 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 26 | /*! \brief primitive header */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 27 | struct osmo_prim_hdr { |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 28 | unsigned int sap; /*!< \brief Service Access Point */ |
| 29 | unsigned int primitive; /*!< \brief Primitive number */ |
| 30 | enum osmo_prim_operation operation; /*! \brief Primitive Operation */ |
| 31 | struct msgb *msg; /*!< \brief \ref msgb containing associated data */ |
Harald Welte | 9b21e88 | 2011-06-23 14:14:20 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 34 | /*! \brief initialize a primitive header |
| 35 | * \param[in,out] oph primitive header |
| 36 | * \param[in] sap Service Access Point |
| 37 | * \param[in] primtive Primitive Number |
| 38 | * \param[in] operation Primitive Operation (REQ/RESP/IND/CONF) |
| 39 | * \param[in] msg Message |
| 40 | */ |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 41 | static inline void |
| 42 | osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap, |
| 43 | unsigned int primitive, enum osmo_prim_operation operation, |
| 44 | struct msgb *msg) |
| 45 | { |
| 46 | oph->sap = sap; |
| 47 | oph->primitive = primitive; |
| 48 | oph->operation = operation; |
| 49 | oph->msg = msg; |
| 50 | } |
| 51 | |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 52 | /*! \brief primitive handler callback type */ |
Harald Welte | 5e924a3 | 2011-06-23 15:04:47 +0200 | [diff] [blame] | 53 | typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx); |
Harald Welte | eee3790 | 2011-08-17 16:14:11 +0200 | [diff] [blame] | 54 | |
| 55 | #endif /* OSMO_PRIMITIVE_H */ |