summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2010-08-13 10:50:16 +0200
committerPatrick McHardy <kaber@trash.net>2010-08-13 13:03:42 +0200
commitf04852105cf8dc08065a8a98af927c5d2dd19852 (patch)
treeb21c8ef9da9ab1de0f6b5b9adec60cd1f922321c
parent906820a35e947230c80188c379ac9ea2fd61d02a (diff)
ie: export IE types and construction/parsing functions
Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--include/dect/s_fmt.h144
-rw-r--r--include/s_fmt.h105
-rw-r--r--src/s_msg.c46
3 files changed, 173 insertions, 122 deletions
diff --git a/include/dect/s_fmt.h b/include/dect/s_fmt.h
new file mode 100644
index 0000000..7df2354
--- /dev/null
+++ b/include/dect/s_fmt.h
@@ -0,0 +1,144 @@
+/*
+ * DECT S-Format messages
+ *
+ * Copyright (c) 2009-2010 Patrick McHardy <kaber@trash.net>
+ */
+
+#ifndef _LIBDECT_DECT_S_FMT_H
+#define _LIBDECT_DECT_S_FMT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Information elements
+ */
+
+#define DECT_SFMT_IE_FIXED_LEN 0x80
+#define DECT_SFMT_IE_FIXED_ID_SHIFT 4
+#define DECT_SFMT_IE_FIXED_VAL_MASK 0x0f
+
+/**
+ * Single octet Information Elements
+ */
+enum dect_sfmt_single_octet_ies {
+ DECT_IE_SHIFT = (0x01 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
+ DECT_IE_EXT_PREFIX = (0x02 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
+ DECT_IE_REPEAT_INDICATOR = (0x05 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
+ DECT_IE_DOUBLE_OCTET_ELEMENT = (0x06 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
+};
+
+/**
+ * Single octet extended Information Elements
+ */
+enum dect_sfmt_single_octet_ext_ies {
+ DECT_IE_SENDING_COMPLETE = 0x1 | DECT_IE_EXT_PREFIX,
+ DECT_IE_DELIMITER_REQUEST = 0x2 | DECT_IE_EXT_PREFIX,
+ DECT_IE_USE_TPUI = 0x3 | DECT_IE_EXT_PREFIX,
+};
+
+/**
+ * Double octet Information Elements
+ */
+enum dect_sfmt_double_octet_ies {
+ DECT_IE_BASIC_SERVICE = 0x0 | DECT_IE_DOUBLE_OCTET_ELEMENT,
+ DECT_IE_RELEASE_REASON = 0x2 | DECT_IE_DOUBLE_OCTET_ELEMENT,
+ DECT_IE_SIGNAL = 0x4 | DECT_IE_DOUBLE_OCTET_ELEMENT,
+ DECT_IE_TIMER_RESTART = 0x5 | DECT_IE_DOUBLE_OCTET_ELEMENT,
+ DECT_IE_TEST_HOOK_CONTROL = 0x6 | DECT_IE_DOUBLE_OCTET_ELEMENT,
+ DECT_IE_SINGLE_DISPLAY = 0x8 | DECT_IE_DOUBLE_OCTET_ELEMENT,
+ DECT_IE_SINGLE_KEYPAD = 0x9 | DECT_IE_DOUBLE_OCTET_ELEMENT,
+};
+
+/**
+ * Variable length Information Elements
+ */
+enum dect_sfmt_variable_length_ies {
+ DECT_IE_INFO_TYPE = 0x01,
+ DECT_IE_IDENTITY_TYPE = 0x02,
+ DECT_IE_PORTABLE_IDENTITY = 0x05,
+ DECT_IE_FIXED_IDENTITY = 0x06,
+ DECT_IE_LOCATION_AREA = 0x07,
+ DECT_IE_NWK_ASSIGNED_IDENTITY = 0x09,
+ DECT_IE_AUTH_TYPE = 0x0a,
+ DECT_IE_ALLOCATION_TYPE = 0x0b,
+ DECT_IE_RAND = 0x0c,
+ DECT_IE_RES = 0x0d,
+ DECT_IE_RS = 0x0e,
+ DECT_IE_IWU_ATTRIBUTES = 0x12,
+ DECT_IE_CALL_ATTRIBUTES = 0x13,
+ DECT_IE_SERVICE_CHANGE_INFO = 0x16,
+ DECT_IE_CONNECTION_ATTRIBUTES = 0x17,
+ DECT_IE_CIPHER_INFO = 0x19,
+ DECT_IE_CALL_IDENTITY = 0x1a,
+ DECT_IE_CONNECTION_IDENTITY = 0x1b,
+ DECT_IE_FACILITY = 0x1c,
+ DECT_IE_PROGRESS_INDICATOR = 0x1e,
+ DECT_IE_MMS_GENERIC_HEADER = 0x20,
+ DECT_IE_MMS_OBJECT_HEADER = 0x21,
+ DECT_IE_MMS_EXTENDED_HEADER = 0x22,
+ DECT_IE_TIME_DATE = 0x23,
+ DECT_IE_MULTI_DISPLAY = 0x28,
+ DECT_IE_MULTI_KEYPAD = 0x2c,
+ DECT_IE_FEATURE_ACTIVATE = 0x38,
+ DECT_IE_FEATURE_INDICATE = 0x39,
+ DECT_IE_NETWORK_PARAMETER = 0x41,
+ DECT_IE_EXT_HO_INDICATOR = 0x42,
+ DECT_IE_ZAP_FIELD = 0x52,
+ DECT_IE_SERVICE_CLASS = 0x54,
+ DECT_IE_KEY = 0x56,
+ DECT_IE_REJECT_REASON = 0x60,
+ DECT_IE_SETUP_CAPABILITY = 0x62,
+ DECT_IE_TERMINAL_CAPABILITY = 0x63,
+ DECT_IE_END_TO_END_COMPATIBILITY = 0x64,
+ DECT_IE_RATE_PARAMETERS = 0x65,
+ DECT_IE_TRANSIT_DELAY = 0x66,
+ DECT_IE_WINDOW_SIZE = 0x67,
+ DECT_IE_CALLING_PARTY_NUMBER = 0x6c,
+ DECT_IE_CALLING_PARTY_NAME = 0x6d,
+ DECT_IE_CALLED_PARTY_NUMBER = 0x70,
+ DECT_IE_CALLED_PARTY_SUBADDR = 0x71,
+ DECT_IE_DURATION = 0x72,
+ DECT_IE_SEGMENTED_INFO = 0x75,
+ DECT_IE_ALPHANUMERIC = 0x76,
+ DECT_IE_IWU_TO_IWU = 0x77,
+ DECT_IE_MODEL_IDENTIFIER = 0x78,
+ DECT_IE_IWU_PACKET = 0x7a,
+ DECT_IE_ESCAPE_TO_PROPRIETARY = 0x7b,
+ DECT_IE_CODEC_LIST = 0x7c,
+ DECT_IE_EVENTS_NOTIFICATION = 0x7d,
+ DECT_IE_CALL_INFORMATION = 0x7e,
+ DECT_IE_ESCAPE_FOR_EXTENSION = 0x7f,
+};
+
+struct dect_sfmt_ie {
+ uint8_t *data;
+ uint8_t id;
+ uint8_t len;
+};
+
+/**
+ * S-Format message parsing/construction state
+ */
+enum dect_sfmt_error {
+ DECT_SFMT_OK = 0, /**< No Error */
+ DECT_SFMT_MANDATORY_IE_MISSING = -1, /**< A mandatory IE was missing */
+ DECT_SFMT_MANDATORY_IE_ERROR = -2, /**< A mandatory IE had an internal structural error */
+ DECT_SFMT_INVALID_IE = -3, /**< An invalid IE was passed to message construction */
+};
+
+extern enum dect_sfmt_error dect_build_sfmt_ie(const struct dect_handle *dh, uint8_t type,
+ struct dect_msg_buf *mb,
+ const struct dect_ie_common *ie);
+
+extern enum dect_sfmt_error dect_parse_sfmt_ie_header(struct dect_sfmt_ie *ie,
+ const struct dect_msg_buf *mb);
+extern enum dect_sfmt_error dect_parse_sfmt_ie(const struct dect_handle *dh, uint8_t type,
+ struct dect_ie_common **dst,
+ const struct dect_sfmt_ie *ie);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _LIBDECT_DECT_S_FMT_H */
diff --git a/include/s_fmt.h b/include/s_fmt.h
index 73722f8..8dd634a 100644
--- a/include/s_fmt.h
+++ b/include/s_fmt.h
@@ -8,6 +8,7 @@
#define _LIBDECT_S_FMT_H
#include <dect/ie.h>
+#include <dect/s_fmt.h>
/*
* S-Format message header
@@ -61,92 +62,9 @@ enum dect_clms_msg_types {
* Information elements
*/
-#define DECT_SFMT_IE_FIXED_LEN 0x80
#define DECT_SFMT_IE_FIXED_ID_MASK 0x70
-#define DECT_SFMT_IE_FIXED_ID_SHIFT 4
#define DECT_SFMT_IE_FIXED_VAL_MASK 0x0f
-enum dect_sfmt_single_octet_ies {
- DECT_IE_SHIFT = (0x01 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
- DECT_IE_EXT_PREFIX = (0x02 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
- DECT_IE_REPEAT_INDICATOR = (0x05 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
- DECT_IE_DOUBLE_OCTET_ELEMENT = (0x06 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
-};
-
-enum dect_sfmt_single_octet_ext_ies {
- DECT_IE_SENDING_COMPLETE = 0x1 | DECT_IE_EXT_PREFIX,
- DECT_IE_DELIMITER_REQUEST = 0x2 | DECT_IE_EXT_PREFIX,
- DECT_IE_USE_TPUI = 0x3 | DECT_IE_EXT_PREFIX,
-};
-
-enum dect_sfmt_double_octet_ies {
- DECT_IE_BASIC_SERVICE = 0x0 | DECT_IE_DOUBLE_OCTET_ELEMENT,
- DECT_IE_RELEASE_REASON = 0x2 | DECT_IE_DOUBLE_OCTET_ELEMENT,
- DECT_IE_SIGNAL = 0x4 | DECT_IE_DOUBLE_OCTET_ELEMENT,
- DECT_IE_TIMER_RESTART = 0x5 | DECT_IE_DOUBLE_OCTET_ELEMENT,
- DECT_IE_TEST_HOOK_CONTROL = 0x6 | DECT_IE_DOUBLE_OCTET_ELEMENT,
- DECT_IE_SINGLE_DISPLAY = 0x8 | DECT_IE_DOUBLE_OCTET_ELEMENT,
- DECT_IE_SINGLE_KEYPAD = 0x9 | DECT_IE_DOUBLE_OCTET_ELEMENT,
-};
-
-enum dect_sfmt_variable_length_ies {
- DECT_IE_INFO_TYPE = 0x01,
- DECT_IE_IDENTITY_TYPE = 0x02,
- DECT_IE_PORTABLE_IDENTITY = 0x05,
- DECT_IE_FIXED_IDENTITY = 0x06,
- DECT_IE_LOCATION_AREA = 0x07,
- DECT_IE_NWK_ASSIGNED_IDENTITY = 0x09,
- DECT_IE_AUTH_TYPE = 0x0a,
- DECT_IE_ALLOCATION_TYPE = 0x0b,
- DECT_IE_RAND = 0x0c,
- DECT_IE_RES = 0x0d,
- DECT_IE_RS = 0x0e,
- DECT_IE_IWU_ATTRIBUTES = 0x12,
- DECT_IE_CALL_ATTRIBUTES = 0x13,
- DECT_IE_SERVICE_CHANGE_INFO = 0x16,
- DECT_IE_CONNECTION_ATTRIBUTES = 0x17,
- DECT_IE_CIPHER_INFO = 0x19,
- DECT_IE_CALL_IDENTITY = 0x1a,
- DECT_IE_CONNECTION_IDENTITY = 0x1b,
- DECT_IE_FACILITY = 0x1c,
- DECT_IE_PROGRESS_INDICATOR = 0x1e,
- DECT_IE_MMS_GENERIC_HEADER = 0x20,
- DECT_IE_MMS_OBJECT_HEADER = 0x21,
- DECT_IE_MMS_EXTENDED_HEADER = 0x22,
- DECT_IE_TIME_DATE = 0x23,
- DECT_IE_MULTI_DISPLAY = 0x28,
- DECT_IE_MULTI_KEYPAD = 0x2c,
- DECT_IE_FEATURE_ACTIVATE = 0x38,
- DECT_IE_FEATURE_INDICATE = 0x39,
- DECT_IE_NETWORK_PARAMETER = 0x41,
- DECT_IE_EXT_HO_INDICATOR = 0x42,
- DECT_IE_ZAP_FIELD = 0x52,
- DECT_IE_SERVICE_CLASS = 0x54,
- DECT_IE_KEY = 0x56,
- DECT_IE_REJECT_REASON = 0x60,
- DECT_IE_SETUP_CAPABILITY = 0x62,
- DECT_IE_TERMINAL_CAPABILITY = 0x63,
- DECT_IE_END_TO_END_COMPATIBILITY = 0x64,
- DECT_IE_RATE_PARAMETERS = 0x65,
- DECT_IE_TRANSIT_DELAY = 0x66,
- DECT_IE_WINDOW_SIZE = 0x67,
- DECT_IE_CALLING_PARTY_NUMBER = 0x6c,
- DECT_IE_CALLING_PARTY_NAME = 0x6d,
- DECT_IE_CALLED_PARTY_NUMBER = 0x70,
- DECT_IE_CALLED_PARTY_SUBADDR = 0x71,
- DECT_IE_DURATION = 0x72,
- DECT_IE_SEGMENTED_INFO = 0x75,
- DECT_IE_ALPHANUMERIC = 0x76,
- DECT_IE_IWU_TO_IWU = 0x77,
- DECT_IE_MODEL_IDENTIFIER = 0x78,
- DECT_IE_IWU_PACKET = 0x7a,
- DECT_IE_ESCAPE_TO_PROPRIETARY = 0x7b,
- DECT_IE_CODEC_LIST = 0x7c,
- DECT_IE_EVENTS_NOTIFICATION = 0x7d,
- DECT_IE_CALL_INFORMATION = 0x7e,
- DECT_IE_ESCAPE_FOR_EXTENSION = 0x7f,
-};
-
#define DECT_OCTET_GROUP_END 0x80
/* Repeat indicator */
@@ -351,12 +269,6 @@ struct dect_sfmt_ie_desc {
.flags = DECT_SFMT_IE_END, \
}
-struct dect_sfmt_ie {
- uint8_t *data;
- uint8_t id;
- uint8_t len;
-};
-
struct dect_sfmt_msg_desc {
const char *name;
struct dect_sfmt_ie_desc ie[];
@@ -370,21 +282,6 @@ struct dect_sfmt_msg_desc {
}, \
}
-/**
- * enum dect_sfmt_error - S-Format message parsing/construction state
- *
- * @DECT_SFMT_OK: No error
- * @DECT_SFMT_MANDATORY_IE_MISSING: A mandatory IE was missing
- * @DECT_SFMT_MANDATORY_IE_ERROR: A mandatory IE had an internal structural error
- * @DECT_SFMT_INVALID_IE: An invalid IE was passed to message construction
- */
-enum dect_sfmt_error {
- DECT_SFMT_OK = 0,
- DECT_SFMT_MANDATORY_IE_MISSING = -1,
- DECT_SFMT_MANDATORY_IE_ERROR = -2,
- DECT_SFMT_INVALID_IE = -3,
-};
-
static inline enum dect_reject_reasons dect_sfmt_reject_reason(enum dect_sfmt_error err)
{
switch (err) {
diff --git a/src/s_msg.c b/src/s_msg.c
index cdee320..4b599f2 100644
--- a/src/s_msg.c
+++ b/src/s_msg.c
@@ -2322,8 +2322,9 @@ static void dect_msg_ie_init(const struct dect_sfmt_ie_desc *desc,
#endif
}
-static int dect_parse_sfmt_ie_header(struct dect_sfmt_ie *ie,
- const struct dect_msg_buf *mb)
+enum dect_sfmt_error
+dect_parse_sfmt_ie_header(struct dect_sfmt_ie *ie,
+ const struct dect_msg_buf *mb)
{
uint8_t val;
@@ -2356,6 +2357,7 @@ static int dect_parse_sfmt_ie_header(struct dect_sfmt_ie *ie,
// ie->id, ie->len);
return 0;
}
+EXPORT_SYMBOL(dect_parse_sfmt_ie_header);
static int dect_build_sfmt_ie_header(struct dect_sfmt_ie *dst, uint8_t id)
{
@@ -2378,10 +2380,10 @@ static int dect_build_sfmt_ie_header(struct dect_sfmt_ie *dst, uint8_t id)
return 0;
}
-static int dect_parse_sfmt_ie(const struct dect_handle *dh,
- const struct dect_sfmt_ie_desc *desc,
- struct dect_ie_common **dst,
- struct dect_sfmt_ie *ie)
+enum dect_sfmt_error
+dect_parse_sfmt_ie(const struct dect_handle *dh, uint8_t type,
+ struct dect_ie_common **dst,
+ const const struct dect_sfmt_ie *ie)
{
const struct dect_ie_handler *ieh;
int err = -1;
@@ -2413,6 +2415,7 @@ err1:
sfmt_debug("smsg: IE parsing error\n");
return err;
}
+EXPORT_SYMBOL(dect_parse_sfmt_ie);
static void sfmt_debug_msg(const struct dect_sfmt_msg_desc *mdesc, const char *msg)
{
@@ -2488,7 +2491,7 @@ found:
}
/* Ignore corrupt optional IEs */
- if (dect_parse_sfmt_ie(dh, desc, dst, ie) < 0 &&
+ if (dect_parse_sfmt_ie(dh, desc->type, dst, ie) < 0 &&
dect_rx_status(dh, desc) == DECT_SFMT_IE_MANDATORY)
return DECT_SFMT_MANDATORY_IE_ERROR;
@@ -2511,20 +2514,15 @@ out:
return DECT_SFMT_OK;
}
-static enum dect_sfmt_error
-dect_build_sfmt_ie(const struct dect_handle *dh,
- const struct dect_sfmt_ie_desc *desc,
+enum dect_sfmt_error
+dect_build_sfmt_ie(const struct dect_handle *dh, uint8_t type,
struct dect_msg_buf *mb,
- struct dect_ie_common *ie)
+ const struct dect_ie_common *ie)
{
const struct dect_ie_handler *ieh;
- uint16_t type = desc->type;
struct dect_sfmt_ie dst;
enum dect_sfmt_error err = 0;
- if (dect_tx_status(dh, desc) == DECT_SFMT_IE_NONE)
- return DECT_SFMT_INVALID_IE;
-
if (type == DECT_IE_SINGLE_DISPLAY) {
struct dect_ie_display *display = dect_ie_container(display, ie);
if (display->len > 1)
@@ -2557,6 +2555,18 @@ dect_build_sfmt_ie(const struct dect_handle *dh,
err1:
return err;
}
+EXPORT_SYMBOL(dect_build_sfmt_ie);
+
+static enum dect_sfmt_error
+__dect_build_sfmt_ie(const struct dect_handle *dh,
+ const struct dect_sfmt_ie_desc *desc,
+ struct dect_msg_buf *mb,
+ const struct dect_ie_common *ie)
+{
+ if (dect_tx_status(dh, desc) == DECT_SFMT_IE_NONE)
+ return DECT_SFMT_INVALID_IE;
+ return dect_build_sfmt_ie(dh, desc->type, mb, ie);
+}
enum dect_sfmt_error dect_build_sfmt_msg(const struct dect_handle *dh,
const struct dect_sfmt_msg_desc *mdesc,
@@ -2582,7 +2592,7 @@ enum dect_sfmt_error dect_build_sfmt_msg(const struct dect_handle *dh,
/* Add repeat indicator if more than one element on the list */
if (iel->list->next != NULL) {
- err = dect_build_sfmt_ie(dh, desc, mb, &iel->common);
+ err = __dect_build_sfmt_ie(dh, desc, mb, &iel->common);
if (err != DECT_SFMT_OK)
return err;
}
@@ -2590,12 +2600,12 @@ enum dect_sfmt_error dect_build_sfmt_msg(const struct dect_handle *dh,
assert(desc->flags & DECT_SFMT_IE_REPEAT);
dect_foreach_ie(rsrc, iel) {
- err = dect_build_sfmt_ie(dh, desc, mb, rsrc);
+ err = __dect_build_sfmt_ie(dh, desc, mb, rsrc);
if (err != DECT_SFMT_OK)
return err;
}
} else if (*src != NULL) {
- err = dect_build_sfmt_ie(dh, desc, mb, *src);
+ err = __dect_build_sfmt_ie(dh, desc, mb, *src);
if (err != DECT_SFMT_OK)
return err;
} else {