blob: b370375e8a194237876aa0cc5ec555b572976426 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2019, Infosys Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <pthread.h>
21#include <string.h>
22#include <unistd.h>
23#include <freeDiameter/freeDiameter-host.h>
24#include <freeDiameter/libfdcore.h>
25#include <freeDiameter/libfdproto.h>
26
27#include "log.h"
28#include "err_codes.h"
29#include "message_queues.h"
30#include "ipc_api.h"
31#include "s6a_fd.h"
32#include "s6a.h"
33#include "msgType.h"
34//#include "detach_stage2_info.h"
35#include "hss_message.h"
36
37#define DIAMETER_SUCCESS 2001
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
45
46
47/**
48 * @brief callback handler for clr recvd from hss
49 * Parse clr, state and do cleanup for freediameter
50 * @params callback std
51 * @return error/success
52 */
53int
54clr_resp_callback(struct msg **buf, struct avp *avps, struct session *sess,
55 void *data, enum disp_action *action)
56{
57 struct msg *resp = NULL;
58 struct avp *avp_ptr = NULL;
59 struct s6_incoming_msg_data_t s6_incoming_msgs;
60 struct avp_hdr *avp_header = NULL;
61 unsigned int sess_id_len;
62 unsigned char *sess_id= NULL;
63
64 resp = *buf;
65
66 dump_fd_msg(resp);
67
68 /*read session id and extract ue index*/
69 CHECK_FCT_DO(fd_sess_getsid(sess, &sess_id, (size_t*)&sess_id_len),
70 return S6A_FD_ERROR);
71 log_msg(LOG_INFO, "\n CLR callback ----- >session id=%s \n",sess_id);
72
73
74 /*AVP: Cancellation-Type*/
75 avp_ptr = NULL;
76 fd_msg_search_avp(resp, g_fd_dict_objs.cancellation_type, &avp_ptr);
77 if(NULL != avp_ptr) {
78 fd_msg_avp_hdr(avp_ptr, &avp_header);
79 s6_incoming_msgs.msg_data.clr_Q_msg_m.c_type = avp_header->avp_value->i32;
80 }
81
82 fd_msg_search_avp(resp,g_fd_dict_objs.org_host, &avp_ptr);
83 if(NULL != avp_ptr) {
84 fd_msg_avp_hdr(avp_ptr, &avp_header);
85 memcpy(s6_incoming_msgs.msg_data.clr_Q_msg_m.origin_host,avp_header->avp_value->os.data,sizeof(s6_incoming_msgs.msg_data.clr_Q_msg_m.origin_host));
86 }
87
88 fd_msg_search_avp(resp, g_fd_dict_objs.org_realm, &avp_ptr);
89 if(NULL != avp_ptr) {
90 fd_msg_avp_hdr(avp_ptr, &avp_header);
91 memcpy(s6_incoming_msgs.msg_data.clr_Q_msg_m.origin_realm,avp_header->avp_value->os.data,sizeof(s6_incoming_msgs.msg_data.clr_Q_msg_m.origin_realm));
92 }
93
94 fd_msg_search_avp(resp, g_fd_dict_objs.user_name,&avp_ptr);
95 if(NULL != avp_ptr) {
96 fd_msg_avp_hdr(avp_ptr, &avp_header);
97 memcpy(s6_incoming_msgs.msg_data.clr_Q_msg_m.imsi,avp_header->avp_value->os.data,sizeof(s6_incoming_msgs.msg_data.clr_Q_msg_m.imsi));
98 }
99
100 /*CLA Processing*/
101
102 struct msg *ans, *qry;
103 struct avp * a;
104
105 if (buf == NULL)
106 return EINVAL;
107
108
109 /* Create answer header */
110 qry = *buf;
111 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, buf, 0 ) );
112 ans = *buf;
113
114 /* Set the Origin-Host, Origin-Realm, Result-Code AVPs */
115 CHECK_FCT( fd_msg_rescode_set( ans, "DIAMETER_SUCCESS", NULL, NULL, 1 ) );
116
117 /* Send the answer */
118 CHECK_FCT( fd_msg_send( buf, NULL, NULL ) );
119
120 /*Do cleanup for freediameter*/
121 fd_msg_free(*buf);
122
123 *buf = NULL;
124
125 s6_incoming_msgs.msg_type = cancel_location_request;
126
127 s6_incoming_msgs.destInstAddr = htonl(mmeAppInstanceNum_c);
128 s6_incoming_msgs.srcInstAddr = htonl(s6AppInstanceNum_c);
129
130 /*Send to stage2 queue*/
131 send_tipc_message(g_Q_mme_S6a_fd, mmeAppInstanceNum_c, (char*)&s6_incoming_msgs, S6_READ_MSG_BUF_SIZE);
132
133 return SUCCESS;
134}
135
136/*Handler for CLR coming from built in perf HS*/
137void
138handle_perf_hss_clr(int ue_idx, struct hss_clr_msg *clr)
139{
140 struct s6_incoming_msg_data_t msg;
141
142 msg.msg_type = cancel_location_request;
143 msg.ue_idx = ue_idx;
144 memcpy(&(msg.msg_data.clr_Q_msg_m.c_type), &(clr->cancellation_type), sizeof(clr->cancellation_type));
145 /*Send to stage2 queue*/
146 write_ipc_channel(g_Q_mme_S6a_fd, (char*)&msg, S6_READ_MSG_BUF_SIZE);
147}