void SET_OF_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { if(td && ptr) { asn_SET_OF_specifics_t *specs; asn_TYPE_member_t *elm = td->elements; asn_anonymous_set_ *list = _A_SET_FROM_VOID(ptr); asn_struct_ctx_t *ctx; /* Decoder context */ int i; /* * Could not use set_of_empty() because of (*free) * incompatibility. */ for(i = 0; i < list->count; i++) { void *memb_ptr = list->array[i]; if(memb_ptr) ASN_STRUCT_FREE(*elm->type, memb_ptr); } list->count = 0; /* No meaningful elements left */ asn_set_empty(list); /* Remove (list->array) */ specs = (asn_SET_OF_specifics_t *)td->specifics; ctx = (asn_struct_ctx_t *)((char *)ptr + specs->ctx_offset); if(ctx->ptr) { ASN_STRUCT_FREE(*elm->type, ctx->ptr); ctx->ptr = 0; } if(!contents_only) { FREEMEM(ptr); } } }
void metautils_message_destroy(MESSAGE m) { if (!m) return ; if (m->id != NULL) ASN_STRUCT_FREE(asn_DEF_OCTET_STRING, m->id); if (m->body != NULL) ASN_STRUCT_FREE(asn_DEF_OCTET_STRING, m->body); if (m->version != NULL) ASN_STRUCT_FREE(asn_DEF_OCTET_STRING, m->version); if (m->name != NULL) ASN_STRUCT_FREE(asn_DEF_OCTET_STRING, m->name); m->content.list.free = _free_Parameter; asn_set_empty(&(m->content.list)); free(m); }
void SET_OF_free(const asn_TYPE_descriptor_t *td, void *ptr, enum asn_struct_free_method method) { if(td && ptr) { const asn_SET_OF_specifics_t *specs; asn_TYPE_member_t *elm = td->elements; asn_anonymous_set_ *list = _A_SET_FROM_VOID(ptr); asn_struct_ctx_t *ctx; /* Decoder context */ int i; /* * Could not use set_of_empty() because of (*free) * incompatibility. */ for(i = 0; i < list->count; i++) { void *memb_ptr = list->array[i]; if(memb_ptr) ASN_STRUCT_FREE(*elm->type, memb_ptr); } list->count = 0; /* No meaningful elements left */ asn_set_empty(list); /* Remove (list->array) */ specs = (const asn_SET_OF_specifics_t *)td->specifics; ctx = (asn_struct_ctx_t *)((char *)ptr + specs->ctx_offset); if(ctx->ptr) { ASN_STRUCT_FREE(*elm->type, ctx->ptr); ctx->ptr = 0; } switch(method) { case ASFM_FREE_EVERYTHING: FREEMEM(ptr); break; case ASFM_FREE_UNDERLYING: break; case ASFM_FREE_UNDERLYING_AND_RESET: memset(ptr, 0, specs->struct_size); break; } } }
static gssize abstract_sequence_unmarshall(const struct abstract_sequence_handler_s *h, GSList ** list, const void *asn1_encoded, gsize asn1_encoded_size, GError ** err) { gssize consumed; void *result = NULL; gint i = 0, max = 0; asn_dec_rval_t decRet; struct anonymous_sequence_s *abstract_sequence; GSList *api_result = NULL; void func_free(void *d) { if (!d) return; h->clean_ASN1(d, FALSE); } if (!asn1_encoded || !list) { GSETERROR(err, "Invalid parameter"); return -1; } asn_codec_ctx_t codecCtx = {0}; codecCtx.max_stack_size = ASN1C_MAX_STACK; decRet = ber_decode(&codecCtx, h->asn1_descriptor, &(result), asn1_encoded, asn1_encoded_size); switch (decRet.code) { case RC_OK: abstract_sequence = (struct anonymous_sequence_s *) result; /*fill the list with the content of the array */ for (i = 0, max = abstract_sequence->list.count; i < max; i++) { void *api_structure; api_structure = g_malloc0(h->api_size); if (!h->map_ASN1_to_API(abstract_sequence->list.array[i], api_structure)) { GSETERROR(err,"Element of type [%s] ASN-to-API conversion error", h->type_name); if (api_structure) h->clean_API(api_structure); abstract_sequence->list.free = &func_free; asn_set_empty(abstract_sequence); free(abstract_sequence); abstract_sequence = NULL; if (api_result) { g_slist_foreach(api_result, api_gclean, h->clean_API); g_slist_free(api_result); } return -1; } api_result = g_slist_prepend(api_result, api_structure); } abstract_sequence->list.free = &func_free; asn_set_empty(abstract_sequence); free(abstract_sequence); abstract_sequence = NULL; *list = metautils_gslist_precat(*list, api_result); consumed = decRet.consumed; return consumed; case RC_FAIL: GSETERROR(err, "sequence unmarshalling error (%"G_GSIZE_FORMAT" consumed)", decRet.consumed); return -1; case RC_WMORE: GSETERROR(err, "sequence unmarshalling error (uncomplete)"); return 0; default: GSETERROR(err, "Serialisation produced an unknow return code : %d", decRet.code); return -1; } return -1; }
void bcch_dlsch_sib1(BCCH_DL_SCH_Message_t *msg, MCC_MNC_Digit_t mcc_val[3], MCC_MNC_Digit_t mnc_val[2], uint8_t tac_val[2], uint8_t cid_val[4], int freq_band) { bzero(msg, sizeof(BCCH_DL_SCH_Message_t)); msg->message.present = BCCH_DL_SCH_MessageType_PR_c1; msg->message.choice.c1.present = BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1; SystemInformationBlockType1_t *sib1 = &(msg->message.choice.c1.choice.systemInformationBlockType1); PLMN_IdentityInfo_t *PLMN_identity_info = calloc(1, sizeof(PLMN_IdentityInfo_t)); MCC_t *mcc = calloc(1, sizeof(MCC_t)); PLMN_identity_info->plmn_Identity.mcc = mcc; asn_set_empty(&mcc->list); for (int i=0;i<3;i++) { ASN_SEQUENCE_ADD(&mcc->list,dup_digit(mcc_val[i])); } asn_set_empty(&PLMN_identity_info->plmn_Identity.mnc.list); for (int i=0;i<2;i++) { ASN_SEQUENCE_ADD(&PLMN_identity_info->plmn_Identity.mnc.list,dup_digit(mnc_val[i])); } PLMN_identity_info->cellReservedForOperatorUse=PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved; ASN_SEQUENCE_ADD(&sib1->cellAccessRelatedInfo.plmn_IdentityList.list,PLMN_identity_info); sib1->cellAccessRelatedInfo.trackingAreaCode.buf=malloc(2); for (int i=0;i<2;i++) { sib1->cellAccessRelatedInfo.trackingAreaCode.buf[i] = tac_val[i]; } sib1->cellAccessRelatedInfo.trackingAreaCode.size=2; sib1->cellAccessRelatedInfo.trackingAreaCode.bits_unused=0; sib1->cellAccessRelatedInfo.cellIdentity.buf=malloc(4); for (int i=0;i<4;i++) { sib1->cellAccessRelatedInfo.cellIdentity.buf[i] = cid_val[i]; } sib1->cellAccessRelatedInfo.cellIdentity.size=4; sib1->cellAccessRelatedInfo.cellIdentity.bits_unused=4; sib1->cellAccessRelatedInfo.cellBarred=SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_barred; sib1->cellAccessRelatedInfo.intraFreqReselection=SystemInformationBlockType1__cellAccessRelatedInfo__intraFreqReselection_allowed; sib1->cellAccessRelatedInfo.csg_Indication=0; sib1->cellSelectionInfo.q_RxLevMin=-60; sib1->cellSelectionInfo.q_RxLevMinOffset=NULL; sib1->freqBandIndicator = (long int) freq_band; SchedulingInfo_t *schedulingInfo_3 = calloc(2, sizeof(SchedulingInfo_t)); SchedulingInfo_t *schedulingInfo_6 = calloc(2, sizeof(SchedulingInfo_t)); SIB_Type_t *sib_type_3 = calloc(1, sizeof(SIB_Type_t)); SIB_Type_t *sib_type_6 = calloc(1, sizeof(SIB_Type_t)); schedulingInfo_3->si_Periodicity=SchedulingInfo__si_Periodicity_rf16; *sib_type_3=SIB_Type_sibType3; ASN_SEQUENCE_ADD(&schedulingInfo_3->sib_MappingInfo.list,sib_type_3); ASN_SEQUENCE_ADD(&sib1->schedulingInfoList.list,schedulingInfo_3); schedulingInfo_6->si_Periodicity=SchedulingInfo__si_Periodicity_rf64; *sib_type_6=SIB_Type_sibType6; ASN_SEQUENCE_ADD(&schedulingInfo_6->sib_MappingInfo.list,sib_type_6); ASN_SEQUENCE_ADD(&sib1->schedulingInfoList.list,schedulingInfo_6); sib1->si_WindowLength=SystemInformationBlockType1__si_WindowLength_ms40; sib1->systemInfoValueTag=8; }