blob: 935ce51aea77295b3d86d82ba309ffce9bf564e1 [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Harald Welte9b21e882011-06-23 14:14:20 +02002
Harald Welteeee37902011-08-17 16:14:11 +02003/*! \defgroup prim Osmocom primitives
4 * @{
5 */
6
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +01007/*! \file prim.h */
Harald Welteeee37902011-08-17 16:14:11 +02008
Harald Welte9b21e882011-06-23 14:14:20 +02009#include <stdint.h>
Harald Welte5e924a32011-06-23 15:04:47 +020010#include <osmocom/core/msgb.h>
Harald Welte9b21e882011-06-23 14:14:20 +020011
Andreas Eversberg78122ab2011-09-27 12:06:55 +020012#define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF))
13#define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation)
14
Harald Welteeee37902011-08-17 16:14:11 +020015/*! \brief primitive operation */
Harald Welte9b21e882011-06-23 14:14:20 +020016enum osmo_prim_operation {
Harald Welteeee37902011-08-17 16:14:11 +020017 PRIM_OP_REQUEST, /*!< \brief request */
18 PRIM_OP_RESPONSE, /*!< \brief response */
19 PRIM_OP_INDICATION, /*!< \brief indication */
20 PRIM_OP_CONFIRM, /*!< \brief cofirm */
Harald Welte9b21e882011-06-23 14:14:20 +020021};
22
Harald Welte5e924a32011-06-23 15:04:47 +020023#define _SAP_GSM_SHIFT 24
24
25#define _SAP_GSM_BASE (0x01 << _SAP_GSM_SHIFT)
26#define _SAP_TETRA_BASE (0x02 << _SAP_GSM_SHIFT)
27
Harald Welteeee37902011-08-17 16:14:11 +020028/*! \brief primitive header */
Harald Welte9b21e882011-06-23 14:14:20 +020029struct osmo_prim_hdr {
Harald Welteeee37902011-08-17 16:14:11 +020030 unsigned int sap; /*!< \brief Service Access Point */
31 unsigned int primitive; /*!< \brief Primitive number */
32 enum osmo_prim_operation operation; /*! \brief Primitive Operation */
33 struct msgb *msg; /*!< \brief \ref msgb containing associated data */
Harald Welte9b21e882011-06-23 14:14:20 +020034};
35
Harald Welteeee37902011-08-17 16:14:11 +020036/*! \brief initialize a primitive header
37 * \param[in,out] oph primitive header
38 * \param[in] sap Service Access Point
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010039 * \param[in] primitive Primitive Number
Harald Welteeee37902011-08-17 16:14:11 +020040 * \param[in] operation Primitive Operation (REQ/RESP/IND/CONF)
41 * \param[in] msg Message
42 */
Harald Welte5e924a32011-06-23 15:04:47 +020043static inline void
44osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap,
45 unsigned int primitive, enum osmo_prim_operation operation,
46 struct msgb *msg)
47{
48 oph->sap = sap;
49 oph->primitive = primitive;
50 oph->operation = operation;
51 oph->msg = msg;
52}
53
Harald Welteeee37902011-08-17 16:14:11 +020054/*! \brief primitive handler callback type */
Harald Welte5e924a32011-06-23 15:04:47 +020055typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx);
Harald Welteeee37902011-08-17 16:14:11 +020056
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010057/*! @} */