msgfile: Allow to have comments in the simple CSV file
[osmocom-bb.git] / src / gsm0808.c
index 114ddbf..636c211 100644 (file)
 #define BSSMAP_MSG_SIZE 512
 #define BSSMAP_MSG_HEADROOM 128
 
-struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc, uint16_t cc, int lac, int _ci)
+static void put_data_16(uint8_t *data, const uint16_t val)
+{
+       memcpy(data, &val, sizeof(val));
+}
+
+struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc, uint16_t cc, int lac, uint16_t _ci)
 {
        uint8_t *data;
-       uint16_t *ci;
+       uint8_t *ci;
        struct msgb* msg;
        struct gsm48_loc_area_id *lai;
 
@@ -56,8 +61,8 @@ struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc, uint16_t cc
        lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
        gsm48_generate_lai(lai, cc, nc, lac);
 
-       ci = (uint16_t *) msgb_put(msg, 2);
-       *ci = htons(_ci);
+       ci = msgb_put(msg, 2);
+       put_data_16(ci, htons(_ci));
 
        /* copy the layer3 data */
        data = msgb_put(msg, msgb_l3len(msg_l3) + 2);
@@ -187,7 +192,7 @@ struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
        return msg;
 }
 
-struct msgb *gsm0808_create_assignment_completed(struct gsm_lchan *lchan, uint8_t rr_cause,
+struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
                                                 uint8_t chosen_channel, uint8_t encr_alg_id,
                                                 uint8_t speech_mode)
 {
@@ -266,6 +271,14 @@ struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause)
        return msg;
 }
 
+void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id)
+{
+       uint8_t *hh = msgb_push(msg, 3);
+       hh[0] = BSSAP_MSG_DTAP;
+       hh[1] = link_id;
+       hh[2] = msg->len - 3;
+}
+
 static const struct tlv_definition bss_att_tlvdef = {
        .def = {
                [GSM0808_IE_IMSI]                   = { TLV_TYPE_TLV },
@@ -275,7 +288,7 @@ static const struct tlv_definition bss_att_tlvdef = {
                [GSM0808_IE_EMLPP_PRIORITY]         = { TLV_TYPE_TV },
                [GSM0808_IE_CHANNEL_TYPE]           = { TLV_TYPE_TLV },
                [GSM0808_IE_PRIORITY]               = { TLV_TYPE_TLV },
-               [GSM0808_IE_CIRCUIT_IDENTITY_CODE]  = { TLV_TYPE_TV },
+               [GSM0808_IE_CIRCUIT_IDENTITY_CODE]  = { TLV_TYPE_FIXED, 2 },
                [GSM0808_IE_DOWNLINK_DTX_FLAG]      = { TLV_TYPE_TV },
                [GSM0808_IE_INTERFERENCE_BAND_TO_USE] = { TLV_TYPE_TV },
                [GSM0808_IE_CLASSMARK_INFORMATION_T2] = { TLV_TYPE_TLV },
@@ -283,12 +296,14 @@ static const struct tlv_definition bss_att_tlvdef = {
                [GSM0808_IE_TALKER_FLAG]            = { TLV_TYPE_T },
                [GSM0808_IE_CONFIG_EVO_INDI]        = { TLV_TYPE_TV },
                [GSM0808_IE_LSA_ACCESS_CTRL_SUPPR]  = { TLV_TYPE_TV },
-               [GSM0808_IE_SERVICE_HANDOVER]       = { TLV_TYPE_TV},
+               [GSM0808_IE_SERVICE_HANDOVER]       = { TLV_TYPE_TLV },
                [GSM0808_IE_ENCRYPTION_INFORMATION] = { TLV_TYPE_TLV },
                [GSM0808_IE_CIPHER_RESPONSE_MODE]   = { TLV_TYPE_TV },
                [GSM0808_IE_CELL_IDENTIFIER]        = { TLV_TYPE_TLV },
                [GSM0808_IE_CHOSEN_CHANNEL]         = { TLV_TYPE_TV },
                [GSM0808_IE_LAYER_3_INFORMATION]    = { TLV_TYPE_TLV },
+               [GSM0808_IE_SPEECH_VERSION]         = { TLV_TYPE_TV },
+               [GSM0808_IE_CHOSEN_ENCR_ALG]        = { TLV_TYPE_TV },
        },
 };