blob: b1026fe3fd168291ff5a36f4ebf2c7a8fd146976 [file] [log] [blame]
Harald Welte9b21e882011-06-23 14:14:20 +02001#ifndef OSMO_PRIMITIVE_H
2#define OSMO_PRIMITIVE_H
3
Harald Welteeee37902011-08-17 16:14:11 +02004/*! \defgroup prim Osmocom primitives
5 * @{
6 */
7
8/*! \file prim.c */
9
Harald Welte9b21e882011-06-23 14:14:20 +020010#include <stdint.h>
Harald Welte5e924a32011-06-23 15:04:47 +020011#include <osmocom/core/msgb.h>
Harald Welte9b21e882011-06-23 14:14:20 +020012
Andreas Eversberg78122ab2011-09-27 12:06:55 +020013#define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF))
14#define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation)
15
Harald Welteeee37902011-08-17 16:14:11 +020016/*! \brief primitive operation */
Harald Welte9b21e882011-06-23 14:14:20 +020017enum osmo_prim_operation {
Harald Welteeee37902011-08-17 16:14:11 +020018 PRIM_OP_REQUEST, /*!< \brief request */
19 PRIM_OP_RESPONSE, /*!< \brief response */
20 PRIM_OP_INDICATION, /*!< \brief indication */
21 PRIM_OP_CONFIRM, /*!< \brief cofirm */
Harald Welte9b21e882011-06-23 14:14:20 +020022};
23
Harald Welte5e924a32011-06-23 15:04:47 +020024#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 Welteeee37902011-08-17 16:14:11 +020029/*! \brief primitive header */
Harald Welte9b21e882011-06-23 14:14:20 +020030struct osmo_prim_hdr {
Harald Welteeee37902011-08-17 16:14:11 +020031 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 Welte9b21e882011-06-23 14:14:20 +020035};
36
Harald Welteeee37902011-08-17 16:14:11 +020037/*! \brief initialize a primitive header
38 * \param[in,out] oph primitive header
39 * \param[in] sap Service Access Point
40 * \param[in] primtive Primitive Number
41 * \param[in] operation Primitive Operation (REQ/RESP/IND/CONF)
42 * \param[in] msg Message
43 */
Harald Welte5e924a32011-06-23 15:04:47 +020044static inline void
45osmo_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 Welteeee37902011-08-17 16:14:11 +020055/*! \brief primitive handler callback type */
Harald Welte5e924a32011-06-23 15:04:47 +020056typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx);
Harald Welteeee37902011-08-17 16:14:11 +020057
58#endif /* OSMO_PRIMITIVE_H */