blob: 0ffe8e21a04a05e2b1710cdf84df8a9f426468a9 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
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
20#include <stdio.h>
21#include <stdlib.h>
22#include <pthread.h>
23#include <string.h>
24#include <unistd.h>
25#include <freeDiameter/freeDiameter-host.h>
26#include <freeDiameter/libfdcore.h>
27#include <freeDiameter/libfdproto.h>
28
29#include "log.h"
30#include "err_codes.h"
31#include "message_queues.h"
32#include "ipc_api.h"
33#include "s6a_fd.h"
34#include "s6a.h"
35#include "msgType.h"
36//#include "detach_stage2_info.h"
37#include "hss_message.h"
38
39/** Global and externs**/
40extern struct fd_dict_objects g_fd_dict_objs;
41extern struct fd_dict_data g_fd_dict_data;
42extern int g_Q_mme_S6a_fd;
43/**global and externs end**/
44
45static
46void send_to_stage2(struct s6_incoming_msg_data_t *incoming_msg_p)
47{
48 /*Send to stage2 queue*/
49 write_ipc_channel(g_Q_mme_S6a_fd, (char*)incoming_msg_p,
50 S6_READ_MSG_BUF_SIZE);
51}
52
53/**
54 * @brief callback handler for purge answer recvd from hss
55 * Parse purge answer, state and do cleanup for freediameter
56 * @params callback std
57 * @return error/success
58 */
59int
60purge_resp_callback(struct msg **buf, struct avp *avps, struct session *sess,
61 void *data, enum disp_action *action)
62{
63 struct msg *resp = NULL;
64 struct avp *avp_ptr = NULL;
65 struct s6_incoming_msg_data_t s6_incoming_msgs;
66 struct avp_hdr *avp_header = NULL;
67 unsigned int sess_id_len;
68 unsigned char *sess_id= NULL;
69
70 resp = *buf;
71
72 dump_fd_msg(resp);
73
74 /*read session id and extract ue index*/
75 CHECK_FCT_DO(fd_sess_getsid(sess, &sess_id, (size_t*)&sess_id_len),
76 return S6A_FD_ERROR);
77 log_msg(LOG_INFO, "\nPurge callback ----- >session id=%s \n",sess_id);
78
79 s6_incoming_msgs.msg_type = purge_answser;
80 s6_incoming_msgs.ue_idx = get_ue_idx_from_fd_resp(sess_id, sess_id_len);
81
82 /*AVP: Result-Code*/
83 avp_ptr = NULL;
84 fd_msg_search_avp(resp, g_fd_dict_objs.res_code, &avp_ptr);
85
86 if(NULL != avp_ptr) {
87 fd_msg_avp_hdr(avp_ptr, &avp_header);
88 s6_incoming_msgs.msg_data.purge_resp_Q_msg_m.status = avp_header->avp_value->u32;
89
90 if (SUCCESS != s6_incoming_msgs.msg_data.purge_resp_Q_msg_m.status) {
91 s6_incoming_msgs.msg_data.purge_resp_Q_msg_m.status = S6A_FD_ERROR;
92 }
93 } else {
94 struct fd_result res;
95 avp_ptr = NULL;
96
97 fd_msg_search_avp(resp, g_fd_dict_objs.exp_res,
98 &avp_ptr);
99
100 if (NULL != avp_ptr) {
101 s6_incoming_msgs.msg_data.purge_resp_Q_msg_m.status = S6A_FD_ERROR;
102 }
103
104 if (parse_fd_result(avp_ptr, &res) != SUCCESS) {
105 s6_incoming_msgs.msg_data.purge_resp_Q_msg_m.status = S6A_FD_ERROR;
106 }
107 s6_incoming_msgs.msg_data.purge_resp_Q_msg_m.status =res.result_code;
108 }
109
110 /*Inform response to mme-app*/
111 send_to_stage2(&s6_incoming_msgs);
112
113 /*Do cleanup for freediameter*/
114 fd_msg_free(*buf);
115
116 *buf = NULL;
117
118 return SUCCESS;
119}
120
121/*Handler for AIA coming from built in perf HS*/
122void
123handle_perf_hss_purge_resp(int ue_idx)
124{
125 struct s6_incoming_msg_data_t resp;
126
127 resp.msg_type = purge_answser;
128 resp.ue_idx = ue_idx;
129 resp.msg_data.purge_resp_Q_msg_m.status = 0;
130
131 send_to_stage2(&resp);
132}