summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/core/prim.h14
-rw-r--r--src/prim.c18
2 files changed, 32 insertions, 0 deletions
diff --git a/include/osmocom/core/prim.h b/include/osmocom/core/prim.h
index 99a71d5d..f04e15e1 100644
--- a/include/osmocom/core/prim.h
+++ b/include/osmocom/core/prim.h
@@ -57,4 +57,18 @@ osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap,
/*! \brief primitive handler callback type */
typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx);
+/*! \brief magic value to be used as final record of \ref
+ * osmo_prim_event_map */
+#define OSMO_NO_EVENT 0xFFFFFFFF
+
+/*! \brief single entry in a SAP/PRIM/OP -> EVENT map */
+struct osmo_prim_event_map {
+ unsigned int sap; /*!< SAP to match */
+ unsigned int primitive; /*!< primtiive to match */
+ enum osmo_prim_operation operation; /*!< operation to match */
+ uint32_t event; /*!< event as result if above match */
+};
+
+uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph,
+ const struct osmo_prim_event_map *maps);
/*! @} */
diff --git a/src/prim.c b/src/prim.c
index 3f41c416..5851f6f5 100644
--- a/src/prim.c
+++ b/src/prim.c
@@ -10,3 +10,21 @@ const struct value_string osmo_prim_op_names[5] = {
{ PRIM_OP_CONFIRM, "confirm" },
{ 0, NULL }
};
+
+/*! \brief resolve the (fsm) event for a given primitive using a map
+ * \param[in] oph primitive header used as key for match
+ * \param[in] maps list of mappings from primitive to event
+ * \returns event determined by map; \ref OSMO_NO_EVENT if no match */
+uint32_t osmo_event_for_prim(const struct osmo_prim_hdr *oph,
+ const struct osmo_prim_event_map *maps)
+{
+ const struct osmo_prim_event_map *map;
+
+ for (map = maps; map->event != OSMO_NO_EVENT; map++) {
+ if (map->sap == oph->sap &&
+ map->primitive == oph->primitive &&
+ map->operation == oph->operation)
+ return map->event;
+ }
+ return OSMO_NO_EVENT;
+}