libosmocore 1.13.1.1-afb4 Osmocom core library

prim.h
Go to the documentation of this file.
1#pragma once
2
19#include <stdint.h>
20#include <osmocom/core/msgb.h>
21
22#define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF))
23#define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation)
24
26 enum osmo_prim_operation {
27 PRIM_OP_REQUEST,
28 PRIM_OP_RESPONSE,
29 PRIM_OP_INDICATION,
30 PRIM_OP_CONFIRM,
31};
32
33 extern const struct value_string osmo_prim_op_names[];
34 static inline const char *osmo_prim_operation_name(enum osmo_prim_operation val)
35{
36 return get_value_string(osmo_prim_op_names, val);
37}
38
40#define _SAP_GSM_SHIFT 24
41
42#define _SAP_GSM_BASE (0x01 << _SAP_GSM_SHIFT)
43#define _SAP_TETRA_BASE (0x02 << _SAP_GSM_SHIFT)
44#define _SAP_SS7_BASE (0x03 << _SAP_GSM_SHIFT)
45
47 struct osmo_prim_hdr {
48 unsigned int sap;
49 unsigned int primitive;
50 enum osmo_prim_operation operation;
51 struct msgb *msg;
58};
59
67 static inline void
68 osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap,
69 unsigned int primitive, enum osmo_prim_operation operation,
70 struct msgb *msg)
71{
72 oph->sap = sap;
73 oph->primitive = primitive;
74 oph->operation = operation;
75 oph->msg = msg;
76}
77
79 typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx);
80
83#define OSMO_NO_EVENT 0xFFFFFFFF
84
86 struct osmo_prim_event_map {
87 unsigned int sap;
88 unsigned int primitive;
89 enum osmo_prim_operation operation;
90 uint32_t event;
91};
92
93uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph,
94 const struct osmo_prim_event_map *maps);
osmo_prim_operation
osmo_prim_operation
primitive operation
Definition: prim.h:26
osmo_event_for_prim
uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph, const struct osmo_prim_event_map *maps)
resolve the (fsm) event for a given primitive using a map
Definition: prim.c:29
osmo_prim_operation_name
static const char * osmo_prim_operation_name(enum osmo_prim_operation val)
The upper 8 byte of the technology, the lower 24 bits for the SAP.
Definition: prim.h:34
osmo_prim_cb
int(* osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx)
primitive handler callback type
Definition: prim.h:79
osmo_prim_op_names
const struct value_string osmo_prim_op_names[]
human-readable string mapping for osmo_prim_operation
Definition: prim.c:17
osmo_prim_init
static void osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap, unsigned int primitive, enum osmo_prim_operation operation, struct msgb *msg)
Convenience function to initialize a primitive header.
Definition: prim.h:68
PRIM_OP_INDICATION
@ PRIM_OP_INDICATION
indication
Definition: prim.h:29
PRIM_OP_CONFIRM
@ PRIM_OP_CONFIRM
confirm
Definition: prim.h:30
PRIM_OP_REQUEST
@ PRIM_OP_REQUEST
request
Definition: prim.h:27
PRIM_OP_RESPONSE
@ PRIM_OP_RESPONSE
response
Definition: prim.h:28
get_value_string
const char * get_value_string(const struct value_string *vs, uint32_t val)
get human-readable string for given value
Definition: utils.c:63
msg
uint8_t msg[0]
msgb.h
msgb
Osmocom message buffer.
Definition: msgb.h:31
osmo_prim_event_map
single entry in a SAP/PRIM/OP -> EVENT map
Definition: prim.h:86
osmo_prim_event_map::event
uint32_t event
event as result if above match
Definition: prim.h:90
osmo_prim_event_map::sap
unsigned int sap
SAP to match.
Definition: prim.h:87
osmo_prim_event_map::primitive
unsigned int primitive
primtiive to match
Definition: prim.h:88
osmo_prim_event_map::operation
enum osmo_prim_operation operation
operation to match
Definition: prim.h:89
osmo_prim_hdr
Osmocom primitive header.
Definition: prim.h:47
osmo_prim_hdr::msg
struct msgb * msg
Primitive Operation.
Definition: prim.h:51
osmo_prim_hdr::operation
enum osmo_prim_operation operation
Definition: prim.h:50
osmo_prim_hdr::primitive
unsigned int primitive
Primitive number.
Definition: prim.h:49
osmo_prim_hdr::sap
unsigned int sap
Service Access Point Identifier.
Definition: prim.h:48
value_string
A mapping between human-readable string and numeric value.
Definition: utils.h:51