diff --git a/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c b/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c index e97d56224c752b05944fecfe21bba79ec77db2a5..cc61f2049acb69fe48887a56da10fa1ae93cfbda 100644 --- a/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c +++ b/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c @@ -210,7 +210,7 @@ nwGtpv1uCreateAndSendMsg( NwGtpv1uStackT *thiz, NwU32T peerIp, NwU16T peerPort, *((NwU32T *) msgHdr) = htonl(pMsg->teid); msgHdr += 4; - GTPU_DEBUG("nwGtpv1uCreateAndSendMsg to teid %u\n", pMsg->teid); + GTPU_DEBUG("nwGtpv1uCreateAndSendMsg to teid %u length %d\n", pMsg->teid, pMsg->msgLen); if(pMsg->seqNumFlag || pMsg->extHdrFlag || pMsg->npduNumFlag) { *((NwU16T *) msgHdr) = (pMsg->seqNumFlag ? htons(pMsg->seqNum) : 0x0000); diff --git a/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1uMsg.c b/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1uMsg.c index a5e8bff3ef5a1457f9850bd422b468e6d996573a..80fa3648468d1a0496c28f28f76c6f7a39f1330d 100644 --- a/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1uMsg.c +++ b/openair-cn/GTPV1-U/nw-gtpv1u/src/NwGtpv1uMsg.c @@ -120,7 +120,8 @@ nwGtpv1uGpduMsgNew( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle, NW_OUT NwGtpv1uMsgHandleT *phMsg) { NwGtpv1uStackT *pStack = (NwGtpv1uStackT *) hGtpuStackHandle; - NwGtpv1uMsgT *pMsg; + NwGtpv1uMsgT *pMsg; + NwU32T header_len = 0; if(gpGtpv1uMsgPool) { pMsg = gpGtpv1uMsgPool; @@ -130,26 +131,57 @@ nwGtpv1uGpduMsgNew( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle, } if(pMsg) { + // Version field: This field is used to determine the version of the GTP-U protocol. + // The version number shall be set to '1'. pMsg->version = NW_GTPU_VERSION; + // Protocol Type (PT): This bit is used as a protocol discriminator between GTP (when PT is '1') + // and GTP' (when PT is '0'). GTP is described in this document and the GTP' protocol in 3GPP TS 32.295 [8]. + // Note that the interpretation of the header fields may be different in GTP' than in GTP. pMsg->protocolType = NW_GTP_PROTOCOL_TYPE_GTP; + // Extension Header flag (E): This flag indicates the presence of a meaningful value of the Next Extension + // Header field. When it is set to '0', the Next Extension Header field either is not present or, if present, + // shall not be interpreted. pMsg->extHdrFlag = NW_FALSE; + // Sequence number flag (S): This flag indicates the presence of a meaningful value of the Sequence Number field. + // When it is set to '0', the Sequence Number field either is not present or, if present, shall not be interpreted. + // When it is set to '1', the Sequence Number field is present, and shall be interpreted, as described below in + // this section. + // For the Echo Request, Echo Response, Error Indication and Supported Extension Headers Notification + // messages, the S flag shall be set to '1'. Since the use of Sequence Numbers is optional for G-PDUs, the PGW, + // SGW, ePDG and eNodeB should set the flag to '0'. However, when a G-PDU (T-PDU+header) is being relayed + // by the Indirect Data Forwarding for Inter RAT HO procedure, then if the received G-PDU has the S flag set to + // '1', then the relaying entity shall set S flag to '1' and forward the G-PDU (T-PDU+header). In an End marker + // message the S flag shall be set to '0'. pMsg->seqNumFlag = (seqNumFlag? NW_TRUE : NW_FALSE); - pMsg->npduNumFlag = NW_FALSE; - pMsg->msgType = NW_GTP_GPDU; - pMsg->teid = teid; pMsg->seqNum = seqNum; + // N-PDU Number flag (PN): This flag indicates the presence of a meaningful value of the N-PDU Number field. + // When it is set to '0', the N-PDU Number field either is not present, or, if present, shall not be interpreted. + // When it is set to '1', the N-PDU Number field is present, and shall be interpreted. + pMsg->npduNumFlag = NW_FALSE; pMsg->npduNum = 0x00; - pMsg->nextExtHdrType= 0x00; + // Message Type: This field indicates the type of GTP-U message. + pMsg->msgType = NW_GTP_GPDU; + // Length: This field indicates the length in octets of the payload, i.e. the rest of the packet following the + // mandatory part of the GTP header (that is the first 8 octets). + // The Sequence Number, the N-PDU Number or any Extension headers shall be considered to be part of the payload, + // i.e. included in the length count. + header_len = ((pMsg->seqNumFlag || pMsg->npduNumFlag || pMsg->extHdrFlag ) ? + NW_GTPV1U_EPC_SPECIFIC_HEADER_SIZE : NW_GTPV1U_EPC_MIN_HEADER_SIZE); pMsg->msgLen = ((pMsg->seqNumFlag || pMsg->npduNumFlag || pMsg->extHdrFlag ) ? - NW_GTPV1U_EPC_SPECIFIC_HEADER_SIZE : (NW_GTPV1U_EPC_SPECIFIC_HEADER_SIZE - 4)); - - memcpy(pMsg->msgBuf + pMsg->msgLen, tpdu, tpduLength); - pMsg->msgLen += tpduLength; - pMsg->msgLen = pMsg->msgLen - ((pMsg->seqNumFlag || pMsg->npduNumFlag - || pMsg->extHdrFlag ) ? - NW_GTPV1U_EPC_SPECIFIC_HEADER_SIZE : (NW_GTPV1U_EPC_SPECIFIC_HEADER_SIZE - 4)); + (NW_GTPV1U_EPC_SPECIFIC_HEADER_SIZE - NW_GTPV1U_EPC_MIN_HEADER_SIZE) + tpduLength : tpduLength); + + // Tunnel Endpoint Identifier (TEID): This field unambiguously identifies a tunnel endpoint in the receiving + // GTP-U protocol entity. The receiving end side of a GTP tunnel locally assigns the TEID value the transmitting + // side has to use. The TEID shall be used by the receiving entity to find the PDP context, except for the + // following cases: + // - The Echo Request/Response and Supported Extension Headers notification messages, where the Tunnel + // Endpoint Identifier shall be set to all zeroes. + // - The Error Indication message where the Tunnel Endpoint Identifier shall be set to all zeros. + pMsg->teid = teid; + pMsg->nextExtHdrType= 0x00; + memcpy(pMsg->msgBuf + header_len, tpdu, tpduLength); *phMsg = (NwGtpv1uMsgHandleT) pMsg; return NW_GTPV1U_OK; }