feat: create cook branch

This commit is contained in:
zhangsz
2025-03-08 16:40:56 +08:00
parent 9a139c52c6
commit 025a455e17
70 changed files with 3603 additions and 11829 deletions

View File

@@ -28,7 +28,6 @@ static long gx_start_ts = 0;
static int gx_rec_ccr( struct msg ** msg, struct avp * avp, struct session * sess, void * opaque, enum disp_action * act);
static void gx_rec_cca(void *para, struct msg **msg);
_gy_port *gy_get_port_by_cxt_id(char *cxt_id);
static struct disp_hdl * ccr_cb_hdl = NULL; /* handler for ccr req cb */
//static struct disp_hdl * cca_cb_hdl = NULL; /* handler for cca req cb */
@@ -187,35 +186,10 @@ static void gy_port_init(_gy_port *gy_port_ptr, int index)
return ;
}
// start==================================
static int print_duplicated_sess_id(const char *cxt_id)
{
int loop=0;
FILE *fpSess=NULL;
fpSess = fopen("../log/dul_sess_id.txt","a");
if(fpSess == NULL)
return 0;
fprintf(fpSess,"now ts=%ld, sess: %s\r\n", ts_sec, cxt_id);
fclose(fpSess);
return 1;
}
int gy_assign_port(char *cxt_id)
{
int i, index, retval = INVALID_GY_PORT;
_gy_port *gy_port_ptr = NULL;
// check if session id already in use========start
gy_port_ptr = gy_get_port_by_cxt_id(cxt_id);
if (gy_port_ptr != NULL)
{
print_duplicated_sess_id(cxt_id);
return retval;
}
CHECK_POSIX_DO( pthread_mutex_lock(&gy_port_lock), { ASSERT(0); } );
@@ -270,7 +244,6 @@ int gy_release_port(unsigned short index)
if(gy_port_ptr->used_flag)
{
pthread_mutex_lock(&sess_hash_mutx);
if(g_sess_hash != NULL)
g_hash_table_remove(g_sess_hash, gy_port_ptr->context_id);// delete hash index
pthread_mutex_unlock(&sess_hash_mutx);
@@ -464,26 +437,24 @@ int free_gx_sm(struct gx_sm_t *sm)
int fd_get_session_id(char *src_buf, char *dst_buf, int flag)
{
//int len;
char *first_off, *second_off, *third_off;
int len;
//second_off = strchr(first_off+1, ';');
//third_off = strchr(second_off+1, ';');
//len = third_off - second_off -1;
first_off = strchr(src_buf, ';');
second_off = strchr(first_off+1, ';');
third_off = strchr(second_off+1, ';');
len = third_off - second_off -1;
//if(flag == 0)
/*if(0)
if(0)
{
memcpy(dst_buf, second_off+1, len);
dst_buf[len] = '\0';
}*/
}
if(1)
{
char *first_off;//, *second_off, *third_off;
first_off = strchr(src_buf, ';');
strcpy(dst_buf, first_off+1);
}
return 1;
}
@@ -777,7 +748,7 @@ static int gx_parse_cca( struct msg ** msg)
if(gy_msg.request_type == RT_TERMINATE_REQUEST ||
gy_msg.request_type == RT_EVENT_REQUEST ||
(cca_ptr->result != 2001 && gy_msg.request_type != RT_UPDATE_REQUEST))
cca_ptr->result != 2001)
{
unsigned int gy_port;
@@ -825,8 +796,7 @@ static int gx_parse_ccr( struct msg ** msg, struct gy_msg *gy_ptr)
memcpy(sess_id, avphdr->avp_value->os.data, avphdr->avp_value->os.len);
sess_id[avphdr->avp_value->os.len] = '\0';
//sprintf(sess_id, "%s",avphdr->avp_value->os.data);
//fd_get_session_id(sess_id, gy_ptr->cxt_id, 0);
strcpy(gy_ptr->cxt_id, sess_id);
fd_get_session_id(sess_id, gy_ptr->cxt_id, 0);
}
}
@@ -1016,6 +986,22 @@ static int gx_parse_ccr( struct msg ** msg, struct gy_msg *gy_ptr)
}
}
/* 3GPP-User-Location-Info */
struct dict_object *tgpp_user_loc_info = NULL;
SEARCH_AVP_("3GPP-User-Location-Info", 10415, &tgpp_user_loc_info);
PARSE_GRPAVP_STR(groupedavp_sub, tgpp_user_loc_info, avp, avphdr, "Parse CCR 3GPP-User-Location-Info", avphdr->avp_value->os.data)
if(avphdr != NULL )
{
if(avphdr->avp_value != NULL)
{
if((avphdr->avp_value->os.data != NULL) && (avphdr->avp_value->os.data[0]==0x82))// TAI and ECGI
{
memcpy(&gy_ptr->msg_body.ccr.cellid, &avphdr->avp_value->os.data[1], 5);// mcc, mnc and tac
gy_ptr->msg_body.ccr.cellid[5] = 0x00;
gy_ptr->msg_body.ccr.cellid[6] = avphdr->avp_value->os.data[12];// CellId
}
}
}
}
else
{
@@ -1274,7 +1260,8 @@ static int gx_parse_ccr( struct msg ** msg, struct gy_msg *gy_ptr)
PARSE_AVP_U32(ccr_msg, multiple_services_indicator, avp, avphdr, "Parse CCR Multiple-Services-Indicator", avphdr->avp_value->u32)
/* Multiple-Services-Credit-Control */
//gy_ptr->msg_body.ccr.mscc_presented = 0;
gy_ptr->msg_body.ccr.mscc_presented = 0;
gy_ptr->msg_body.ccr.used_unit = 0;
struct dict_object *multiple_services_credit_control = NULL;
SEARCH_AVP_("Multiple-Services-Credit-Control", 0, &multiple_services_credit_control);
CHECK_FCT( fd_msg_search_avp ( ccr_msg, multiple_services_credit_control, &groupedavp) );
@@ -1285,7 +1272,7 @@ static int gx_parse_ccr( struct msg ** msg, struct gy_msg *gy_ptr)
{
LOG_N("fj Parse CCR Multiple-Services-Credit-Control");
//gy_ptr->msg_body.ccr.mscc_presented = 1;
gy_ptr->msg_body.ccr.mscc_presented = 1;
/* Requested-Service-Unit */
struct dict_object *requested_service_unit = NULL;
SEARCH_AVP_("Requested-Service-Unit", 0, &requested_service_unit);
@@ -1455,7 +1442,7 @@ int gx_send_cca(_gy_msg *gy_ptr)
long granted_value = gy_ptr->msg_body.cca.grant_value;
int port = gy_ptr->fd_port;
_gy_port *gy_port = NULL;
long valid_time_len = 900;
//long valid_time_len = 900;
gy_port = gy_get_port_space(port);
if(gy_port == NULL)
@@ -1492,23 +1479,23 @@ int gx_send_cca(_gy_msg *gy_ptr)
{
EN_AVP_U32(result_code, gy_ptr->msg_body.cca.result, ans, "fj CCA Result-Code");
}
/*else if (gy_ptr->msg_body.ccr.mscc_presented==0)
else if (gy_ptr->msg_body.ccr.mscc_presented==0)
{
int result = gy_ptr->msg_body.cca.result;
if (result < 2001)
{
result = 2001;
}
else if (resutl == 4012)
{
result = 4547;
}
else if (resutl != 2001)
//else if (result == 4012)
//{
// result = 4547;
//}
else if (result != 2001)
{
result = 5012;
}
EN_AVP_U32(result_code, result, ans, "fj CCA Result-Code");
}*/
}
else
{
CHECK_FCT_DO( fd_msg_rescode_set( ans, "DIAMETER_SUCCESS", NULL, NULL, 1 ), goto out );
@@ -1527,7 +1514,7 @@ int gx_send_cca(_gy_msg *gy_ptr)
EN_AVP_U32(check_balance_result, gy_ptr->msg_body.cca.check_balance_result, ans, "fj CCA check_balance_result");
}
}
else// if (gy_ptr->msg_body.ccr.mscc_presented)
else if(gy_ptr->msg_body.ccr.mscc_presented > 0)
/* Multiple-Services-Credit-Control */
{
CHECK_FCT_DO( fd_msg_avp_new ( multiple_services_credit_control, 0, &grpavp ), goto out );
@@ -1564,7 +1551,7 @@ int gx_send_cca(_gy_msg *gy_ptr)
}
struct dict_object *valid_time = NULL;
EN_GRPAVP_U32("Validity-Time", 0, valid_time, valid_time_len);
EN_GRPAVP_U32("Validity-Time", 0, valid_time, gy_ptr->msg_body.cca.validity_time);//valid_time_len);
if (gy_ptr->request_type != RT_TERMINATE_REQUEST)
{
@@ -1607,14 +1594,7 @@ int gx_send_cca(_gy_msg *gy_ptr)
EN_GRPAVP_U32("Volume-Quota-Threshold", 10415, volume_threshold, gy_ptr->msg_body.cca.volume_threshold);
struct dict_object *quota_hold_time = NULL;
EN_GRPAVP_U32("Quota-Holding-Time", 10415, quota_hold_time, gy_ptr->msg_body.cca.time_threshold + 10);
if(1)
{
struct dict_object *time_threshold = NULL;
EN_GRPAVP_U32("Time-Quota-Threshold", 10415, time_threshold, gy_ptr->msg_body.cca.time_threshold);
}
EN_GRPAVP_U32("Quota-Holding-Time", 10415, quota_hold_time, gy_ptr->msg_body.cca.time_threshold);
}
CHECK_FCT_DO( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, grpavp ), goto out );
@@ -1835,7 +1815,7 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
gx_stat_increase_send_ccr(msg_ptr->request_type);
/* Create the request from template */
CHECK_FCT_DO( fd_msg_new( cmd_r, MSGFL_ALLOC_ETEID, &req ), goto out1 );
CHECK_FCT_DO( fd_msg_new( cmd_r, MSGFL_ALLOC_ETEID, &req ), goto out );
/* set application id */
{
@@ -1892,32 +1872,11 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_FIRST_CHILD, avp ), goto out );
}
char *pRealm = g_sh_conf_ext.pi_diamid_realm_peer, *pHost = g_sh_conf_ext.pi_diamid_peer;
if ((msg_ptr->service_type == ST_CS_SMS) || (msg_ptr->service_type == ST_CS_VOICE))
{
GetRoDiamIdPeer(&pRealm, &pHost, (msg_ptr->service_type == ST_CS_SMS)?1:0);
}
if (pRealm == NULL || pHost == NULL)
{
LOG_N("fj gx_send_ccr_real, no link available, pRealm[%p], pHost[%p]", pRealm, pHost);
return 0;
}
/*if ((msg_ptr->service_type == ST_CS_SMS) && (g_rosms_conf_ext.pi_diamid_realm_peer!=NULL) && (g_rosms_conf_ext.pi_diamid_peer!=NULL))
{
pRealm = g_rosms_conf_ext.pi_diamid_realm_peer;
pHost = g_rosms_conf_ext.pi_diamid_peer;
}
else if ((msg_ptr->service_type == ST_CS_VOICE) && (g_rovoice_conf_ext.pi_diamid_realm_peer!=NULL) && (g_rovoice_conf_ext.pi_diamid_peer!=NULL))
{
pRealm = g_rovoice_conf_ext.pi_diamid_realm_peer;
pHost = g_rovoice_conf_ext.pi_diamid_peer;
}*/
/* Destination-Realm */
EN_AVP_STR(dest_realm, pRealm, req, "fj CCR Destination-Realm Ok");
EN_AVP_STR(dest_realm, g_sh_conf_ext.pi_diamid_realm_peer, req, "fj CCR Destination-Realm Ok");
/* Destination-Host */
EN_AVP_STR(dest_host, pHost, req, "fj CCR Destination-Host-Ok");
EN_AVP_STR(dest_host, g_sh_conf_ext.pi_diamid_peer, req, "fj CCR Destination-Host-Ok");
/* Origin-Host & Origin-Realm */
CHECK_FCT_DO( fd_msg_add_origin ( req, 0 ), goto out );
@@ -1928,14 +1887,12 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
/* Service-Context-ID */
if(msg_ptr->service_type == ST_CS_SMS)
{
//EN_AVP_STR(service_cxt_id, "agrandtech_sms@3gpp.org", req, "fj CCR Service-Context-ID Ok");
EN_AVP_STR(service_cxt_id, fd_g_config->service_context_sms, req, "fj CCR Service-Context-ID Ok");
EN_AVP_STR(service_cxt_id, "agrandtech_sms@3gpp.org", req, "fj CCR Service-Context-ID Ok");
//EN_AVP_STR(route_record, "ocsclient.seagullCTF.org", req , "fj CCR Route-Record OK");
}
else
{
//EN_AVP_STR(service_cxt_id, "agrandtech_ro@3gpp.org", req, "fj CCR Service-Context-ID Ok");
EN_AVP_STR(service_cxt_id, fd_g_config->service_context_voice, req, "fj CCR Service-Context-ID Ok");
EN_AVP_STR(service_cxt_id, "agrandtech_ro@3gpp.org", req, "fj CCR Service-Context-ID Ok");
}
/* CC-Request-Type */
@@ -2092,7 +2049,7 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
struct dict_object *service_specific_info = NULL;
SEARCH_AVP_("Service-Specific-Info", SH_VND_ID, &service_specific_info);
CHECK_FCT_DO( fd_msg_avp_new ( service_specific_info, 0, &grpavp_sub2 ), goto out);
{ /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪӦ<D2AA>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
{ /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪӦ<D2AA>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
EN_GRPAVP_U32_("Service-Specific-Type", SH_VND_ID, dict_obj_tmp, 6006, grpavp_sub2)
EN_GRPAVP_STR("Service-Specific-Data", SH_VND_ID, dict_obj_tmp, msg_ptr->msg_body.ccr.cellid, grpavp_sub2)
CHECK_FCT_DO( fd_msg_avp_add( grpavp_sub1, MSG_BRW_LAST_CHILD, grpavp_sub2 ), goto out );
@@ -2108,7 +2065,6 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
EN_GRPAVP_U32_("Node-Functionality", SH_VND_ID, dict_obj_tmp, 6, grpavp_sub1)
if(msg_ptr->msg_body.ccr.cellid_presented == 1)
{
@@ -2116,7 +2072,7 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
struct dict_object *service_specific_info = NULL;
SEARCH_AVP_("Service-Specific-Info", SH_VND_ID, &service_specific_info);
CHECK_FCT_DO( fd_msg_avp_new ( service_specific_info, 0, &grpavp_sub2 ), goto out);
{ /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪӦ<D2AA>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
{ /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪӦ<D2AA>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
EN_GRPAVP_U32_("Service-Specific-Type", SH_VND_ID, dict_obj_tmp, 6006, grpavp_sub2)
EN_GRPAVP_STR("Service-Specific-Data", SH_VND_ID, dict_obj_tmp, msg_ptr->msg_body.ccr.cellid, grpavp_sub2)
CHECK_FCT_DO( fd_msg_avp_add( grpavp_sub1, MSG_BRW_LAST_CHILD, grpavp_sub2 ), goto out );
@@ -2154,7 +2110,7 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
EN_GRPAVP_STR("Originating-IOI", SH_VND_ID, dict_obj_tmp, fd_g_config->cnf_diamid, grpavp_sub2)
// EN_GRPAVP_STR("Originating-IOI", SH_VND_ID, dict_obj_tmp, "agrandtech_ocs@3gpp.org", grpavp_sub2)
EN_GRPAVP_STR("Terminating-IOI", SH_VND_ID, dict_obj_tmp, pHost, grpavp_sub2)
EN_GRPAVP_STR("Terminating-IOI", SH_VND_ID, dict_obj_tmp, g_sh_conf_ext.pi_diamid_peer, grpavp_sub2)
CHECK_FCT_DO( fd_msg_avp_add( grpavp_sub1, MSG_BRW_LAST_CHILD, grpavp_sub2 ), goto out );
}
@@ -2192,23 +2148,7 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
}
}
if(msg_ptr->msg_body.ccr.cellid_presented == 1)
{
if (msg_ptr->msg_body.ccr.cellid[3] == 'F')
{
char mcc[8]="";
strncpy(mcc, msg_ptr->msg_body.ccr.cellid, 3);
sprintf(tmp_buf, "3GPP-GERAN;cgi-3gpp=%s%s", mcc, &msg_ptr->msg_body.ccr.cellid[4]);
}
else
{
sprintf(tmp_buf, "3GPP-GERAN;cgi-3gpp=%s", msg_ptr->msg_body.ccr.cellid);
}
}
else
{
sprintf(tmp_buf, "XDSL;'location-info=%s'", phostAddr );
}
EN_GRPAVP_STR("Access-Network-Information", SH_VND_ID, dict_obj_tmp, tmp_buf, grpavp_sub1)
if(msg_ptr->msg_body.ccr.role_of_node == 2)
@@ -2623,9 +2563,6 @@ int gx_send_ccr_real(struct gx_sm_t **sm , struct dict_object *cmd_r, _gy_msg *m
CHECK_FCT_DO( fd_msg_send( &req, gx_rec_cca, NULL ), goto out );
out:
if(req != NULL)
fd_msg_free(req);
out1:
return 1;
}
@@ -3231,7 +3168,7 @@ int gx_send_ccr_from_client(struct gy_msg *gy_ptr)
gy_port_ptr->service_type = gy_ptr->request_type;
gy_port_ptr->as_client = 1;
fd_sess_destroy(&gy_sess[sh_port]);
gy_sess[sh_port] = NULL;
}
else
@@ -3281,17 +3218,7 @@ int gx_release_port_for_timerout(unsigned short pid)
}
CHECK_POSIX_DO( pthread_mutex_lock(&gy_port_lock), { ASSERT(0); } );
if(1)
{
gy_port_init(gy_port, pid);
gy_space.used_ports --;
}
else
{
gy_release_port(pid);
}
CHECK_POSIX_DO( pthread_mutex_unlock(&gy_port_lock), { ASSERT(0); } );
return 1;
}