blob: 88ae08b5cf555485f782850d2c90ed8f6ef7c938 [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 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02005 * \file prim.h */
Harald Welteeee37902011-08-17 16:14:11 +02006
Harald Welte9b21e882011-06-23 14:14:20 +02007#include <stdint.h>
Harald Welte5e924a32011-06-23 15:04:47 +02008#include <osmocom/core/msgb.h>
Harald Welte9b21e882011-06-23 14:14:20 +02009
Andreas Eversberg78122ab2011-09-27 12:06:55 +020010#define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF))
11#define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation)
12
Neels Hofmeyr87e45502017-06-20 00:17:59 +020013/*! primitive operation */
Harald Welte9b21e882011-06-23 14:14:20 +020014enum osmo_prim_operation {
Neels Hofmeyr87e45502017-06-20 00:17:59 +020015 PRIM_OP_REQUEST, /*!< request */
16 PRIM_OP_RESPONSE, /*!< response */
17 PRIM_OP_INDICATION, /*!< indication */
18 PRIM_OP_CONFIRM, /*!< confirm */
Harald Welte9b21e882011-06-23 14:14:20 +020019};
20
Harald Weltec959afd2015-12-25 17:14:07 +010021extern const struct value_string osmo_prim_op_names[5];
Harald Weltea2db75f2015-12-22 22:11:27 +010022
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)
Harald Weltea2db75f2015-12-22 22:11:27 +010027#define _SAP_SS7_BASE (0x03 << _SAP_GSM_SHIFT)
Harald Welte5e924a32011-06-23 15:04:47 +020028
Neels Hofmeyr87e45502017-06-20 00:17:59 +020029/*! primitive header */
Harald Welte9b21e882011-06-23 14:14:20 +020030struct osmo_prim_hdr {
Neels Hofmeyr87e45502017-06-20 00:17:59 +020031 unsigned int sap; /*!< Service Access Point */
32 unsigned int primitive; /*!< Primitive number */
33 enum osmo_prim_operation operation; /*! Primitive Operation */
34 struct msgb *msg; /*!< \ref msgb containing associated data */
Harald Welte9b21e882011-06-23 14:14:20 +020035};
36
Neels Hofmeyr87e45502017-06-20 00:17:59 +020037/*! initialize a primitive header
Harald Welteeee37902011-08-17 16:14:11 +020038 * \param[in,out] oph primitive header
39 * \param[in] sap Service Access Point
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010040 * \param[in] primitive Primitive Number
Harald Welteeee37902011-08-17 16:14:11 +020041 * \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
Neels Hofmeyr87e45502017-06-20 00:17:59 +020055/*! 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
Neels Hofmeyr87e45502017-06-20 00:17:59 +020058/*! magic value to be used as final record of \ref
Harald Welteacd08fe2017-04-08 23:35:24 +020059 * osmo_prim_event_map */
60#define OSMO_NO_EVENT 0xFFFFFFFF
61
Neels Hofmeyr87e45502017-06-20 00:17:59 +020062/*! single entry in a SAP/PRIM/OP -> EVENT map */
Harald Welteacd08fe2017-04-08 23:35:24 +020063struct osmo_prim_event_map {
64 unsigned int sap; /*!< SAP to match */
65 unsigned int primitive; /*!< primtiive to match */
66 enum osmo_prim_operation operation; /*!< operation to match */
67 uint32_t event; /*!< event as result if above match */
68};
69
70uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph,
71 const struct osmo_prim_event_map *maps);
Katerina Barone-Adesic28c6a02013-02-15 13:27:59 +010072/*! @} */