aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorStefan Sperling <ssperling@sysmocom.de>2018-11-07 16:33:39 +0100
committerStefan Sperling <ssperling@sysmocom.de>2018-11-15 15:57:59 +0100
commitc5721545c6cd69effcef612a14c01aa4be89adde (patch)
tree97fd63dfe4a622a5a4385517ebbef68ca6a190bb /include
parent60509688527efdf2a90b2d4241034a9775898940 (diff)
use enums consistently instead of falling back to int
The two existing enums defined in gprs_sndcp_xid.h, for protocol and data compression algorithm numbers respectively, were assigned to 'int' variables when their values were copied to other structures. This prevented the compiler from checking the enum value coverage during switch statements and also tripped up Coverity scans looking for enum value mismatch problems. So instead of copying enums to ints, make use of the enums throughout. Structures which can contain values from both enums now use a union of both, forcing us to be very explicit about which set of values we are dealing with. Change-Id: I3771a5c59f4e6fee24083b3c914965baf192cbd7 Depends: If6f3598cd6da4643ff2214e21c0d21f6eff0eb67 Depends: I8444c1ed052707c76a979fb06cb018ac678defa7 Related: CID#149102
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/sgsn/gprs_sndcp_comp.h6
-rw-r--r--include/osmocom/sgsn/gprs_sndcp_xid.h36
2 files changed, 24 insertions, 18 deletions
diff --git a/include/osmocom/sgsn/gprs_sndcp_comp.h b/include/osmocom/sgsn/gprs_sndcp_comp.h
index c04f7d49..e01a9d72 100644
--- a/include/osmocom/sgsn/gprs_sndcp_comp.h
+++ b/include/osmocom/sgsn/gprs_sndcp_comp.h
@@ -41,9 +41,9 @@ struct gprs_sndcp_comp {
uint8_t comp[MAX_COMP]; /* see also: 6.5.1.1.5 and 6.6.1.1.5 */
/* Algorithm parameters */
- int algo; /* Algorithm type (see gprs_sndcp_xid.h) */
- int compclass; /* See gprs_sndcp_xid.h/c */
- void *state; /* Algorithm status and parameters */
+ union gprs_sndcp_comp_algo algo;
+ enum gprs_sndcp_xid_param_types compclass; /* See gprs_sndcp_xid.h/c */
+ void *state; /* Algorithm status and parameters */
};
#define MAX_COMP 16 /* Maximum number of possible pcomp/dcomp values */
diff --git a/include/osmocom/sgsn/gprs_sndcp_xid.h b/include/osmocom/sgsn/gprs_sndcp_xid.h
index e64bc523..0dce43e4 100644
--- a/include/osmocom/sgsn/gprs_sndcp_xid.h
+++ b/include/osmocom/sgsn/gprs_sndcp_xid.h
@@ -32,6 +32,24 @@
#define MAX_NSAPI 11 /* Maximum number usable NSAPIs */
#define MAX_ROHC 16 /* Maximum number of ROHC compression profiles */
+/* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */
+enum gprs_sndcp_hdr_comp_algo {
+ RFC_1144, /* TCP/IP header compression, see also 6.5.2 */
+ RFC_2507, /* TCP/UDP/IP header compression, see also: 6.5.3 */
+ ROHC /* Robust Header Compression, see also 6.5.4 */
+};
+
+/* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */
+enum gprs_sndcp_data_comp_algo {
+ V42BIS, /* V.42bis data compression, see also 6.6.2 */
+ V44 /* V44 data compression, see also: 6.6.3 */
+};
+
+union gprs_sndcp_comp_algo {
+ enum gprs_sndcp_hdr_comp_algo pcomp;
+ enum gprs_sndcp_data_comp_algo dcomp;
+};
+
/* According to: 3GPP TS 44.065, 6.5.1.1 Format of the protocol control
* information compression field (Figure 7) and 3GPP TS 44.065,
* 6.6.1.1 Format of the data compression field (Figure 9) */
@@ -45,7 +63,7 @@ struct gprs_sndcp_comp_field {
unsigned int entity;
/* Algorithm identifier, see also: 6.5.1.1.4 and 6.6.1.1.4 */
- int algo;
+ union gprs_sndcp_comp_algo algo;
/* Number of contained PCOMP / DCOMP values */
uint8_t comp_len;
@@ -62,24 +80,12 @@ struct gprs_sndcp_comp_field {
struct gprs_sndcp_dcomp_v44_params *v44_params;
};
-/* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */
-enum gprs_sndcp_hdr_comp_algo {
- RFC_1144, /* TCP/IP header compression, see also 6.5.2 */
- RFC_2507, /* TCP/UDP/IP header compression, see also: 6.5.3 */
- ROHC /* Robust Header Compression, see also 6.5.4 */
-};
-
-/* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */
-enum gprs_sndcp_data_comp_algo {
- V42BIS, /* V.42bis data compression, see also 6.6.2 */
- V44 /* V44 data compression, see also: 6.6.3 */
-};
-
/* According to: 3GPP TS 44.065, 8 SNDCP XID parameters */
enum gprs_sndcp_xid_param_types {
SNDCP_XID_VERSION_NUMBER,
SNDCP_XID_DATA_COMPRESSION, /* See also: subclause 6.6.1 */
SNDCP_XID_PROTOCOL_COMPRESSION, /* See also: subclause 6.5.1 */
+ SNDCP_XID_INVALID_COMPRESSION /* Not part of the spec; this means we found an invalid value */
};
/* According to: 3GPP TS 44.065, 6.5.2.1 Parameters (Table 5) */
@@ -209,7 +215,7 @@ struct llist_head *gprs_sndcp_parse_xid(int *version,
/* Find out to which compression class the specified comp-field belongs
* (header compression or data compression?) */
-int gprs_sndcp_get_compression_class(
+enum gprs_sndcp_xid_param_types gprs_sndcp_get_compression_class(
const struct gprs_sndcp_comp_field *comp_field);
/* Dump a list with SNDCP-XID fields (Debug) */