blob: 7288ba6acd8c842a481efa1874dba4a7f572e89b [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
Neels Hofmeyr87e45502017-06-20 00:17:59 +020015/*! primitive operation */
Harald Welte9b21e882011-06-23 14:14:20 +020016enum osmo_prim_operation {
Neels Hofmeyr87e45502017-06-20 00:17:59 +020017 PRIM_OP_REQUEST, /*!< request */
18 PRIM_OP_RESPONSE, /*!< response */
19 PRIM_OP_INDICATION, /*!< indication */
20 PRIM_OP_CONFIRM, /*!< 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
Neels Hofmeyr87e45502017-06-20 00:17:59 +020031/*! primitive header */
Harald Welte9b21e882011-06-23 14:14:20 +020032struct osmo_prim_hdr {
Neels Hofmeyr87e45502017-06-20 00:17:59 +020033 unsigned int sap; /*!< Service Access Point */
34 unsigned int primitive; /*!< Primitive number */
35 enum osmo_prim_operation operation; /*! Primitive Operation */
36 struct msgb *msg; /*!< \ref msgb containing associated data */
Harald Welte9b21e882011-06-23 14:14:20 +020037};
38
Neels Hofmeyr87e45502017-06-20 00:17:59 +020039/*! initialize a primitive header
Harald Welteeee37902011-08-17 16:14:11 +020040 * \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
Neels Hofmeyr87e45502017-06-20 00:17:59 +020057/*! 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
Neels Hofmeyr87e45502017-06-20 00:17:59 +020060/*! magic value to be used as final record of \ref
Harald Welteacd08fe2017-04-08 23:35:24 +020061 * osmo_prim_event_map */
62#define OSMO_NO_EVENT 0xFFFFFFFF
63
Neels Hofmeyr87e45502017-06-20 00:17:59 +020064/*! single entry in a SAP/PRIM/OP -> EVENT map */
Harald Welteacd08fe2017-04-08 23:35:24 +020065struct osmo_prim_event_map {
66 unsigned int sap; /*!< SAP to match */
67 unsigned int primitive; /*!< primtiive to match */
68 enum osmo_prim_operation operation; /*!< operation to match */
69 uint32_t event; /*!< event as result if above match */
70};
71
72uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph,
73 const struct osmo_prim_event_map *maps);
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010074/*! @} */