blob: 99a71d5db85a91511df1365ff4b4cbb7b4dde6c6 [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 */
Neels Hofmeyrf6d9f372016-01-18 10:44:15 +010020 PRIM_OP_CONFIRM, /*!< \brief confirm */
Harald Welte9b21e882011-06-23 14:14:20 +020021};
22
Harald Weltec959afd2015-12-25 17:14:07 +010023extern const struct value_string osmo_prim_op_names[5];
Harald Weltea2db75f2015-12-22 22:11:27 +010024
Harald Welte5e924a32011-06-23 15:04:47 +020025#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 Weltea2db75f2015-12-22 22:11:27 +010029#define _SAP_SS7_BASE (0x03 << _SAP_GSM_SHIFT)
Harald Welte5e924a32011-06-23 15:04:47 +020030
Harald Welteeee37902011-08-17 16:14:11 +020031/*! \brief primitive header */
Harald Welte9b21e882011-06-23 14:14:20 +020032struct osmo_prim_hdr {
Harald Welteeee37902011-08-17 16:14:11 +020033 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 Welte9b21e882011-06-23 14:14:20 +020037};
38
Harald Welteeee37902011-08-17 16:14:11 +020039/*! \brief initialize a primitive header
40 * \param[in,out] oph primitive header
41 * \param[in] sap Service Access Point
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010042 * \param[in] primitive Primitive Number
Harald Welteeee37902011-08-17 16:14:11 +020043 * \param[in] operation Primitive Operation (REQ/RESP/IND/CONF)
44 * \param[in] msg Message
45 */
Harald Welte5e924a32011-06-23 15:04:47 +020046static inline void
47osmo_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 Welteeee37902011-08-17 16:14:11 +020057/*! \brief primitive handler callback type */
Harald Welte5e924a32011-06-23 15:04:47 +020058typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx);
Harald Welteeee37902011-08-17 16:14:11 +020059
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010060/*! @} */