anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd. |
| 3 | * Copyright (c) 2017 Intel Corporation |
| 4 | * Copyright (c) 2019, Infosys Ltd. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <pthread.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include "log.h" |
| 25 | #include "err_codes.h" |
| 26 | #include "message_queues.h" |
| 27 | #include "ipc_api.h" |
| 28 | #include "s11_structs.h" |
| 29 | #include "msgType.h" |
| 30 | //#include "stage7_info.h" |
| 31 | #include "gtpv2c.h" |
| 32 | #include "gtpv2c_ie.h" |
| 33 | #include "../../gtpV2Codec/gtpV2StackWrappers.h" |
| 34 | |
| 35 | /************************************************************************ |
| 36 | Current file : Stage 7 handler. To listen MB from mme-app and fwd to CP |
| 37 | ATTACH stages : |
| 38 | Stage 1 : IAM-->[stage1 handler]-->AIR, ULR |
| 39 | Stage 2 : AIA, ULA -->[stage2 handler]--> Auth req |
| 40 | Stage 3 : Auth resp-->[stage3 handler]-->Sec mode cmd |
| 41 | Stage 4 : sec mode resp-->[stage4 handler]-->esm infor req |
| 42 | Stage 5 : esm infor resp-->[stage5 handler]-->create session |
| 43 | Stage 6 : create session resp-->[stage6 handler]-->init ctx setup |
| 44 | --> Stage 7 : attach complete-->[stage7 handler]-->modify bearer |
| 45 | **************************************************************************/ |
| 46 | |
| 47 | /****Globals and externs ***/ |
| 48 | |
| 49 | extern int g_s11_fd; |
| 50 | extern struct sockaddr_in g_s11_cp_addr; |
| 51 | extern socklen_t g_s11_serv_size; |
| 52 | /*TODO: S11 protocol sequence number - need to make it atomic. multiple thread to access this*/ |
| 53 | extern volatile uint32_t g_s11_sequence; |
| 54 | static char buf[S11_MBREQ_STAGE7_BUF_SIZE]; |
| 55 | |
| 56 | /*TODO: S11 protocol sequence number - need to make it atomic. multiple thread to access this*/ |
| 57 | extern volatile uint32_t g_s11_sequence; |
| 58 | |
| 59 | struct MsgBuffer* mbReqMsgBuf_p = NULL; |
| 60 | extern struct GtpV2Stack* gtpStack_gp; |
| 61 | /****Global and externs end***/ |
| 62 | /** |
| 63 | * Stage specific message processing. |
| 64 | */ |
| 65 | static int |
| 66 | modify_bearer_processing(struct MB_Q_msg *mb_msg) |
| 67 | { |
| 68 | GtpV2MessageHeader gtpHeader; |
| 69 | gtpHeader.msgType = GTP_MODIFY_BEARER_REQ; |
| 70 | gtpHeader.sequenceNumber = g_s11_sequence; |
| 71 | gtpHeader.teidPresent = true; |
| 72 | gtpHeader.teid = mb_msg->s11_sgw_c_fteid.header.teid_gre; |
| 73 | |
| 74 | g_s11_sequence++; |
| 75 | |
| 76 | ModifyBearerRequestMsgData msgData; |
| 77 | memset(&msgData, 0, sizeof(msgData)); |
| 78 | msgData.bearerContextsToBeModifiedCount = 1; |
| 79 | msgData.bearerContextsToBeModified[0].epsBearerId.epsBearerId = 5; |
| 80 | msgData.bearerContextsToBeModified[0].s1EnodebFTeidIePresent = true; |
| 81 | msgData.bearerContextsToBeModified[0].s1EnodebFTeid.ipv4present = true; |
| 82 | msgData.bearerContextsToBeModified[0].s1EnodebFTeid.interfaceType = mb_msg->s1u_enb_fteid.header.iface_type; |
| 83 | msgData.bearerContextsToBeModified[0].s1EnodebFTeid.teidGreKey = mb_msg->s1u_enb_fteid.header.teid_gre; |
| 84 | msgData.bearerContextsToBeModified[0].s1EnodebFTeid.ipV4Address.ipValue = mb_msg->s1u_enb_fteid.ip.ipv4.s_addr; |
| 85 | |
| 86 | GtpV2Stack_buildGtpV2Message(gtpStack_gp, mbReqMsgBuf_p, >pHeader, &msgData); |
| 87 | sendto(g_s11_fd, |
| 88 | MsgBuffer_getDataPointer(mbReqMsgBuf_p), |
| 89 | MsgBuffer_getBufLen(mbReqMsgBuf_p), 0, |
| 90 | (struct sockaddr*)&g_s11_cp_addr, |
| 91 | g_s11_serv_size); |
| 92 | //TODO " error chk, eagain etc? |
| 93 | log_msg(LOG_INFO, "Modify beader send, len - %d bytes.\n", MsgBuffer_getBufLen(mbReqMsgBuf_p)); |
| 94 | |
| 95 | MsgBuffer_reset(mbReqMsgBuf_p); |
| 96 | |
| 97 | return SUCCESS; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Thread function for stage. |
| 102 | */ |
| 103 | void* |
| 104 | modify_bearer_handler(void *data) |
| 105 | { |
| 106 | log_msg(LOG_INFO, "Modify bearer handler initialized\n"); |
| 107 | |
| 108 | modify_bearer_processing((struct MB_Q_msg *)data); |
| 109 | |
| 110 | return NULL; |
| 111 | } |