ssize_t s1ap_generate_successfull_outcome( uint8_t **buffer, uint32_t *length, e_S1ap_ProcedureCode procedureCode, S1ap_Criticality_t criticality, asn_TYPE_descriptor_t *td, void *sptr) { S1AP_PDU_t pdu; ssize_t encoded; memset(&pdu, 0, sizeof(S1AP_PDU_t)); pdu.present = S1AP_PDU_PR_successfulOutcome; pdu.choice.successfulOutcome.procedureCode = procedureCode; pdu.choice.successfulOutcome.criticality = criticality; ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr); if (asn1_xer_print) { xer_fprint(stdout, &asn_DEF_S1AP_PDU, (void *)&pdu); } /* We can safely free list of IE from sptr */ ASN_STRUCT_FREE_CONTENTS_ONLY(*td, sptr); if ((encoded = aper_encode_to_new_buffer(&asn_DEF_S1AP_PDU, 0, &pdu, (void **)buffer)) < 0) { return -1; } *length = encoded; return encoded; }
static void verify(int testNo, T_t *ti) { asn_enc_rval_t er; asn_dec_rval_t rv; unsigned char buf[20]; T_t *to = 0; fprintf(stderr, "%d IN: { %lu, %lu, %ld, %ld }\n", testNo, i2ul(&ti->unsigned33), i2ul(&ti->unsigned42), i2l(&ti->signed33), i2l(&ti->signed33ext) ); er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf); assert(er.encoded >= 33 + 42 + 33 + 1 + 33); rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0); assert(rv.code == RC_OK); fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); fprintf(stderr, "%d OUT: { %lu, %lu, %ld, %ld } vs { %lu, %lu, %ld, %ld }\n", testNo, i2ul(&ti->unsigned33), i2ul(&ti->unsigned42), i2l(&ti->signed33), i2l(&ti->signed33ext), i2ul(&to->unsigned33), i2ul(&to->unsigned42), i2l(&to->signed33), i2l(&to->signed33ext)); assert(i2ul(&ti->unsigned33) == i2ul(&to->unsigned33)); assert(i2ul(&ti->unsigned42) == i2ul(&to->unsigned42)); assert(i2l(&ti->signed33) == i2l(&to->signed33)); assert(i2l(&ti->signed33ext) == i2l(&to->signed33ext)); xer_fprint(stderr, &asn_DEF_T, ti); xer_fprint(stderr, &asn_DEF_T, to); }
static void verify(int testNo, T_t *ti) { asn_enc_rval_t er; asn_dec_rval_t rv; unsigned char buf[2]; T_t *to = 0; er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf); fprintf(stderr, "%d IN: %d => %zd\n", testNo, ti->present, er.encoded); assert(er.encoded >= 1 && er.encoded <= (ssize_t)(8 * sizeof(buf))); rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0); assert(rv.code == RC_OK); fprintf(stderr, "%d ENC: %2x%2x\n", testNo, buf[0], buf[1]); fprintf(stderr, "%d OUT: %d\n", testNo, ti->present); assert(ti->present == to->present); if(ti->present == T_PR_second) { assert(ti->choice.second == to->choice.second); } else { assert(ti->choice.first.present == to->choice.first.present); assert(ti->choice.first.choice.nothing == to->choice.first.choice.nothing); } xer_fprint(stderr, &asn_DEF_T, ti); xer_fprint(stderr, &asn_DEF_T, to); }
static void verify(int testNo, T_t *ti) { asn_enc_rval_t er; asn_dec_rval_t rv; unsigned char buf[16]; T_t *to = 0; fprintf(stderr, "%d IN: { %ld, %ld, %lu, %lu }\n", testNo, ti->small32range, ti->full32range, ti->unsigned32, ti->unsplit32); er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf); assert(er.encoded == 8 * sizeof(buf)); rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0); assert(rv.code == RC_OK); fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); fprintf(stderr, "%d OUT: { %ld, %ld, %lu, %lu } vs { %ld, %ld, %lu, %lu }\n", testNo, ti->small32range, ti->full32range, ti->unsigned32, ti->unsplit32, to->small32range, to->full32range, to->unsigned32, to->unsplit32); assert(ti->small32range == to->small32range); assert(ti->full32range == to->full32range); assert(ti->unsigned32 == to->unsigned32); assert(ti->unsplit32 == to->unsplit32); xer_fprint(stderr, &asn_DEF_T, ti); xer_fprint(stderr, &asn_DEF_T, to); }
int rua_decode_errorindicationies( ErrorIndicationIEs_t *errorIndicationIEs, ANY_t *any_p) { ErrorIndication_t errorIndication; ErrorIndication_t *errorIndication_p = &errorIndication; int i, decoded = 0; int tempDecoded = 0; assert(any_p != NULL); assert(errorIndicationIEs != NULL); RUA_DEBUG("Decoding message ErrorIndicationIEs (%s:%d)\n", __FILE__, __LINE__); ANY_to_type_aper(any_p, &asn_DEF_ErrorIndication, (void**)&errorIndication_p); for (i = 0; i < errorIndication_p->errorIndication_ies.list.count; i++) { IE_t *ie_p; ie_p = errorIndication_p->errorIndication_ies.list.array[i]; switch(ie_p->id) { case ProtocolIE_ID_id_Cause: { Cause_t cause; Cause_t *cause_p = &cause; tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_Cause, (void**)&cause_p); if (tempDecoded < 0) { RUA_DEBUG("Decoding of IE cause failed\n"); return -1; } decoded += tempDecoded; if (asn1_xer_print) xer_fprint(stdout, &asn_DEF_Cause, cause_p); memcpy(&errorIndicationIEs->cause, cause_p, sizeof(Cause_t)); } break; /* Optional field */ case ProtocolIE_ID_id_CriticalityDiagnostics: { CriticalityDiagnostics_t criticalityDiagnostics; CriticalityDiagnostics_t *criticalityDiagnostics_p = &criticalityDiagnostics; errorIndicationIEs->presenceMask |= ERRORINDICATIONIES_CRITICALITYDIAGNOSTICS_PRESENT; tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_CriticalityDiagnostics, (void**)&criticalityDiagnostics_p); if (tempDecoded < 0) { RUA_DEBUG("Decoding of IE criticalityDiagnostics failed\n"); return -1; } decoded += tempDecoded; if (asn1_xer_print) xer_fprint(stdout, &asn_DEF_CriticalityDiagnostics, criticalityDiagnostics_p); memcpy(&errorIndicationIEs->criticalityDiagnostics, criticalityDiagnostics_p, sizeof(CriticalityDiagnostics_t)); } break; default: RUA_DEBUG("Unknown protocol IE id (%d) for message errorindicationies\n", (int)ie_p->id); return -1; } } return decoded; }
int main() { LDAPMessage_t *req_bind, *req_search, *req_unbind; LDAPMessage_t *rsp_bind, *rsp_search1, *rsp_search2, *rsp_search_done; int sock = accept_single_connection(3389); fprintf(stderr, "Receiving LDAP message...\n"); req_bind = receive_ldap_message(sock); assert(req_bind); assert(req_bind->protocolOp.present == LDAPMessage__protocolOp_PR_bindRequest); assert(req_bind->protocolOp.choice.bindRequest.version == 3); fprintf(stderr, "Received BindRequest...\n"); asn_fprint(stderr, &asn_DEF_LDAPMessage, req_bind); fprintf(stderr, "Sending BindReply...\n"); rsp_bind = bind_response_ok(req_bind->messageID, &req_bind->protocolOp.choice.bindRequest.name); asn_fprint(stderr, &asn_DEF_LDAPMessage, rsp_bind); send_ldap_message(sock, rsp_bind); req_search = receive_ldap_message(sock); assert(req_search->protocolOp.present == LDAPMessage__protocolOp_PR_searchRequest); fprintf(stderr, "Received SearchRequest...\n"); xer_fprint(stderr, &asn_DEF_LDAPMessage, req_search); rsp_search1 = search_result_entry(req_search->messageID, "Lev Walkin", "*****@*****.**", "avatar.jpg"); asn_fprint(stderr, &asn_DEF_LDAPMessage, rsp_search1); send_ldap_message(sock, rsp_search1); rsp_search2 = search_result_entry(req_search->messageID, "Olga Bobrova", "*****@*****.**", NULL); asn_fprint(stderr, &asn_DEF_LDAPMessage, rsp_search2); send_ldap_message(sock, rsp_search2); rsp_search_done = search_result_done(req_search->messageID, &req_search->protocolOp.choice.searchRequest.baseObject); asn_fprint(stderr, &asn_DEF_LDAPMessage, rsp_search_done); send_ldap_message(sock, rsp_search_done); req_unbind = receive_ldap_message(sock); assert(req_unbind->protocolOp.present == LDAPMessage__protocolOp_PR_unbindRequest); xer_fprint(stderr, &asn_DEF_LDAPMessage, req_unbind); ASN_STRUCT_FREE(asn_DEF_LDAPMessage, req_bind); ASN_STRUCT_FREE(asn_DEF_LDAPMessage, req_search); ASN_STRUCT_FREE(asn_DEF_LDAPMessage, req_unbind); ASN_STRUCT_FREE(asn_DEF_LDAPMessage, rsp_bind); ASN_STRUCT_FREE(asn_DEF_LDAPMessage, rsp_search1); ASN_STRUCT_FREE(asn_DEF_LDAPMessage, rsp_search2); ASN_STRUCT_FREE(asn_DEF_LDAPMessage, rsp_search_done); return 0; }
S1ap_IE_t *s1ap_new_ie( S1ap_ProtocolIE_ID_t id, S1ap_Criticality_t criticality, asn_TYPE_descriptor_t *type, void *sptr) { S1ap_IE_t *buff; if ((buff = malloc(sizeof(S1ap_IE_t))) == NULL) { // Possible error on malloc return NULL; } memset((void *)buff, 0, sizeof(S1ap_IE_t)); buff->id = id; buff->criticality = criticality; if (ANY_fromType_aper(&buff->value, type, sptr) < 0) { fprintf(stderr, "Encoding of %s failed\n", type->name); free(buff); return NULL; } if (asn1_xer_print) if (xer_fprint(stdout, &asn_DEF_S1ap_IE, buff) < 0) { free(buff); return NULL; } return buff; }
int mmsClient_createMmsGetNameListRequestAssociationSpecific(long invokeId, ByteBuffer* writeBuffer) { MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = ConfirmedServiceRequest_PR_getNameList; GetNameListRequest_t* request; request = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNameList); request->continueAfter = NULL; request->objectScope.present = GetNameListRequest__objectScope_PR_aaSpecific; request->objectClass.present = ObjectClass_PR_basicObjectClass; asn_long2INTEGER(&request->objectClass.choice.basicObjectClass, ObjectClass__basicObjectClass_namedVariableList); asn_enc_rval_t rval; rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, mmsClient_write_out, (void*) writeBuffer); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return rval.encoded; }
void test_SearchRequest_context() { /// Building a SearchRequest context /// int ret; DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); // Directory Service Message DSMessage_set_seqNumber(msg, 800); DSMessage_set_ackNumber(msg, 0); DSMessage_set_operation(msg, dsop_PR_searchRequest); SearchRequest_set_searchType(msg, SearchType_all); SearchRequest_set_objectName(msg, ObjectName_context); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
/********************************************************************************************** * writeMmsRejectPdu *********************************************************************************************/ static void writeMmsRejectPdu(int* invokeId, int reason, ByteBuffer* response) { MmsPdu_t* mmsPdu = calloc(1, sizeof(MmsPdu_t)); asn_enc_rval_t rval; mmsPdu->present = MmsPdu_PR_rejectPDU; if (invokeId != NULL) { mmsPdu->choice.rejectPDU.originalInvokeID = calloc(1, sizeof(Unsigned32_t)); asn_long2INTEGER(mmsPdu->choice.rejectPDU.originalInvokeID, *invokeId); } if (reason == REJECT_UNRECOGNIZED_SERVICE) { mmsPdu->choice.rejectPDU.rejectReason.present = RejectPDU__rejectReason_PR_confirmedRequestPDU; mmsPdu->choice.rejectPDU.rejectReason.choice.confirmedResponsePDU = RejectPDU__rejectReason__confirmedRequestPDU_unrecognizedService; } else if(reason == REJECT_UNKNOWN_PDU_TYPE) { mmsPdu->choice.rejectPDU.rejectReason.present = RejectPDU__rejectReason_PR_pduError; asn_long2INTEGER(&mmsPdu->choice.rejectPDU.rejectReason.choice.pduError, RejectPDU__rejectReason__pduError_unknownPduType); } else { mmsPdu->choice.rejectPDU.rejectReason.present = RejectPDU__rejectReason_PR_confirmedRequestPDU; mmsPdu->choice.rejectPDU.rejectReason.choice.confirmedResponsePDU = RejectPDU__rejectReason__confirmedRequestPDU_other; } rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,mmsServer_write_out, (void*) response); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); }
void test_NetinfoResponse() { /// Building a NetinfoResponse /// DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dnm); DNMessage_set_seqNumber(msg, 0); DNMessage_set_ackNumber(msg, 600); DNMessage_set_operation(msg, dnop_PR_netinfoResponse); NetinfoResponse_set_ipAddress(msg, "192.168.10.5"); NetinfoResponse_set_netmask(msg, "255.255.255.0"); NetinfoResponse_set_result(msg, DNDSResult_success); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
void test_ModifyResponse() { /// Building a ModifyResponse /// DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); DSMessage_set_seqNumber(msg, 0); DSMessage_set_ackNumber(msg, 300); DSMessage_set_operation(msg, dsop_PR_modifyResponse); ModifyResponse_set_result(msg, DNDSResult_success); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
void test_NetinfoRequest() { /// Building a NetinfoRequest /// DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dnm); DNMessage_set_seqNumber(msg, 600); DNMessage_set_ackNumber(msg, 0); DNMessage_set_operation(msg, dnop_PR_netinfoRequest); uint8_t macAddr[ETH_ALEN] = { 0xd, 0xe, 0xa, 0xd, 0xb, 0xe }; NetinfoRequest_set_ipLocal(msg, "192.168.10.10"); NetinfoRequest_set_macAddr(msg, macAddr); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
void test_DelRequest() { #if 0 /// Building a DelRequest /// DNDSMessage_t *msg; // a DNDS Message DNDSObject_t *objAcl; // a DNDS Object DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); // Directory Service Message DSMessage_set_seqNumber(msg, 200); DSMessage_set_ackNumber(msg, 0); DSMessage_set_operation(msg, dsop_PR_delRequest); DelRequest_set_objectType(msg, DNDSObject_PR_acl, &objAcl); Acl_set_id(objAcl, 1); Acl_set_contextId(objAcl, 2); Acl_set_description(objAcl, "une description", 15); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); #endif }
void test_ModifyRequest() { #if 0 /// Building a ModifyRequest /// DNDSMessage_t *msg; // a DNDS Message DNDSObject_t *objAclGroup; DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); DSMessage_set_seqNumber(msg, 300); DSMessage_set_ackNumber(msg, 0); DSMessage_set_operation(msg, dsop_PR_modifyRequest); ModifyRequest_set_objectType(msg, DNDSObject_PR_aclgroup, &objAclGroup); AclGroup_set_id(objAclGroup, 1); AclGroup_set_contextId(objAclGroup, 1); AclGroup_set_name(objAclGroup, "group-name", 10); AclGroup_set_description(objAclGroup, "a description", 13); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); #endif }
void test_AuthResponse_dnm() { /// Building an AuthRequest /// DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dnm); // Dynamic Network Message DNMessage_set_seqNumber(msg, 0); DNMessage_set_ackNumber(msg, 100); DNMessage_set_operation(msg, dnop_PR_authResponse); AuthResponse_set_result(msg, DNDSResult_success); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
void test_TerminateRequest() { /// Building a TerminateRequest /// DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); DSMessage_set_seqNumber(msg, 0); DSMessage_set_ackNumber(msg, 400); DSMessage_set_operation(msg, dsop_PR_terminateRequest); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
void test_P2pRequest_dnm() { /// Building a P2pRequest /// int ret; uint8_t macAddrSrc[ETH_ALEN] = { 0xe6, 0x1b, 0x23, 0x0c, 0x0c, 0x5d }; uint8_t macAddrDst[ETH_ALEN] = { 0xe6, 0x1b, 0x23, 0x0c, 0x0c, 0x5d }; DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dnm); // Dynamic Network Message DNMessage_set_seqNumber(msg, 801); DNMessage_set_ackNumber(msg, 0); DNMessage_set_operation(msg, dnop_PR_p2pRequest); P2pRequest_set_ipAddrDst(msg, "66.55.44.33"); P2pRequest_set_port(msg, 9000); P2pRequest_set_side(msg, P2pSide_client); P2pRequest_set_macAddrDst(msg, macAddrDst); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
void test_P2pResponse_dnm() { /// Building a P2pRequest /// uint8_t macAddrDst[ETH_ALEN] = { 0xaf, 0xbe, 0xcd, 0xdc, 0xeb, 0xfa }; DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dnm); // Dynamic Network Message DNMessage_set_seqNumber(msg, 0); DNMessage_set_ackNumber(msg, 801); DNMessage_set_operation(msg, dnop_PR_p2pResponse); P2pResponse_set_macAddrDst(msg, macAddrDst); P2pResponse_set_result(msg, DNDSResult_success); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
static int save_object(void *bs, asn_TYPE_descriptor_t *td) { asn_enc_rval_t rval; /* Return value */ int i; rval = der_encode(td, bs, _buf_writer, 0); if (rval.encoded == -1) { fprintf(stderr, "Cannot encode %s: %s\n", rval.failed_type->name, strerror(errno)); assert(rval.encoded != -1); return -1; /* JIC */ } buf[buf_offset++] = 123; /* Finalize with garbage */ asn_fprint(stderr, td, bs); xer_fprint(stderr, td, bs); printf("OUT: ["); for(i = 0; i < buf_offset; i++) printf(" %02x", buf[i]); printf("]\n"); return 0; }
void test_NodeConnectInfo() { /// Building a NodeConnectInfo /// int ret; DNDSMessage_t *msg; DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); // Directory Service Message DSMessage_set_seqNumber(msg, 800); DSMessage_set_ackNumber(msg, 0); //DSMessage_set_operation(msg, dsop_PR_nodeConnectInfo); //NodeConnectInfo_set_certName(msg, "unique_name@context", 19); //NodeConnectInfo_set_ipAddr(msg, "44.128.0.1"); //NodeConnectInfo_set_state(msg, ConnectState_connected); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
test_AddRequest_context() { /// Building context AddRequest /// DNDSMessage_t *msg; DNDSObject_t *obj; DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); DSMessage_set_seqNumber(msg, 0); DSMessage_set_ackNumber(msg, 0); DSMessage_set_operation(msg, dsop_PR_addRequest); AddRequest_set_objectType(msg, DNDSObject_PR_context, &obj); Context_set_clientId(obj, 100); Context_set_description(obj, "home network1", 13); Context_set_network(obj, "44.128.0.0"); Context_set_netmask(obj, "255.255.255.0"); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
test_AddRequest_node() { /// Building node AddRequest /// DNDSMessage_t *msg; DNDSObject_t *obj; DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); DSMessage_set_seqNumber(msg, 0); DSMessage_set_ackNumber(msg, 0); DSMessage_set_operation(msg, dsop_PR_addRequest); AddRequest_set_objectType(msg, DNDSObject_PR_node, &obj); Node_set_contextId(obj, 100); Node_set_description(obj, "voip node 1", 11); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
void test_DNDS_ethernet() { /// Building an message ethernet frame /// DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_ethernet); // ethernet frame uint8_t *frame = strdup("0110101010101"); size_t frame_size = 13; DNDSMessage_set_ethernet(msg, frame, frame_size); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); // XXX free(frame) DNDSMessage_del(msg); }
void test_AuthRequest() { /// Building an AuthRequest /// DNDSMessage_t *msg; // a DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); // Directory Service Message DSMessage_set_seqNumber(msg, 100); DSMessage_set_ackNumber(msg, 0); DSMessage_set_operation(msg, dnop_PR_authRequest); AuthRequest_set_certName(msg, "nib@1", 5); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
bool mmsClient_parseGetNameListResponse(LinkedList* nameList, ByteBuffer* message, uint32_t* invokeId) { MmsPdu_t* mmsPdu = 0; bool moreFollows = false; asn_dec_rval_t rval; /* Decoder return value */ rval = ber_decode(NULL, &asn_DEF_MmsPdu, (void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message)); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { *invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu); if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == ConfirmedServiceResponse_PR_getNameList) { GetNameListResponse_t* response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getNameList); int variableCount; int i; LinkedList element; if ((response->moreFollows != NULL) && (*(response->moreFollows) != 0)) moreFollows = true; if (*nameList == NULL) *nameList = LinkedList_create(); variableCount = response->listOfIdentifier.list.count; element = LinkedList_getLastElement(*nameList); for (i = 0; i < variableCount; i++) { char* variableName = createStringFromBuffer(response->listOfIdentifier.list.array[i]->buf, response->listOfIdentifier.list.array[i]->size); element = LinkedList_insertAfter(element, variableName); } } else { printf("parseMmsGetNameListResponse: NOT A GetNameList RESPONSE!\n"); } } else { printf("parseMmsGetNameListResponse: NOT A CONFIRMED RESPONSE!\n"); } asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return moreFollows; }
void test_SearchResponse() { printf("TEST SEARCH RESPONSE\n"); /// Building a SearchResponse DNDSMessage_t *msg; // A DNDS Message DNDSMessage_new(&msg); DNDSMessage_set_channel(msg, 0); DNDSMessage_set_pdu(msg, pdu_PR_dsm); DSMessage_set_seqNumber(msg, 0); DSMessage_set_ackNumber(msg, 1); DSMessage_set_action(msg, action_listNode); DSMessage_set_operation(msg, dsop_PR_searchResponse); SearchResponse_set_result(msg, DNDSResult_success); SearchResponse_set_searchType(msg, SearchType_object); /* /// objContext DNDSObject_t *objContext; DNDSObject_new(&objContext); DNDSObject_set_objectType(objContext, DNDSObject_PR_context); Context_set_id(objContext, 40); SearchResponse_add_object(msg, objContext); */ /// Node DNDSObject_t *objNode; DNDSObject_new(&objNode); DNDSObject_set_objectType(objNode, DNDSObject_PR_node); // Node_set_contextId(objNode, 10); Node_set_description(objNode, "yo", strlen("yo")); Node_set_uuid(objNode, "abc", strlen("abc")); Node_set_certificate(objNode, "certificate", 11); Node_set_certificateKey(objNode, "key", 3); Node_set_status(objNode, 2); SearchResponse_add_object(msg, objNode); /// Encoding part asn_enc_rval_t ec; // Encoder return value FILE *fp = fopen("dnds.ber", "wb"); // BER output ec = der_encode(&asn_DEF_DNDSMessage, msg, write_out, fp); fclose(fp); xer_fprint(stdout, &asn_DEF_DNDSMessage, msg); DNDSMessage_del(msg); }
int main(int ac, char **av) { /* Declare a pointer to a T1 type */ T1_t *t1; /* Encoder return value */ asn_enc_rval_t ec; /* Allocate an instance of T1 */ t1 = calloc(1, sizeof *t1); assert(t1); /* Assume infinite memory */ /* Prepare a BIT STRING */ (*t1).first.buf = calloc(2, 1); assert((*t1).first.buf); (*t1).first.size = 2; /* 2 bytes */ (*t1).first.buf[0] = 0xc0; /* Set BIT STRING value */ (*t1).first.buf[1] = 0xc0; /* Set BIT STRING value */ (*t1).first.bits_unused = 4; /* Trim unused bits */ /* * Output the resulting structure as PER */ if(ac < 2) { fprintf(stderr,"Specify filename for PER output\n"); } else { const char *filename = av[1]; FILE *fp = fopen(filename,"wb"); /* for PER output */ if(!fp) { perror(filename); exit(71); /* better, EX_OSERR */ } /* Encode T1 as PER */ ec = uper_encode(&asn_DEF_T1,t1,write_out,fp); fclose(fp); if(ec.encoded == -1) { fprintf(stderr,"Could not encode T1 (at %s)\n", ec.failed_type ? ec.failed_type->name : "unknown"); exit(65); /* better, EX_DATAERR */ } else { fprintf(stderr,"Created %s with PER encoded T1\n",filename); } } /* * And print it as XER (XML) */ xer_fprint(stdout, &asn_DEF_T1, t1); return 0; }
int mmsClient_createWriteRequest(uint32_t invokeId, char* domainId, char* itemId, MmsValue* value, ByteBuffer* writeBuffer) { //TODO reuse code to send information report! MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = ConfirmedServiceRequest_PR_write; WriteRequest_t* request = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.write); /* Create list of variable specifications */ request->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable; request->variableAccessSpecification.choice.listOfVariable.list.count = 1; request->variableAccessSpecification.choice.listOfVariable.list.size = 1; request->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**) calloc(1, sizeof(ListOfVariableSeq_t*)); request->variableAccessSpecification.choice.listOfVariable.list.array[0] = (ListOfVariableSeq_t*) createNewDomainVariableSpecification(domainId, itemId); /* Create list of typed data values */ request->listOfData.list.count = 1; request->listOfData.list.size = 1; request->listOfData.list.array = (Data_t**) calloc(1, sizeof(struct Data*)); request->listOfData.list.array[0] = mmsMsg_createBasicDataElement(value); asn_enc_rval_t rval; rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, (asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); if (DEBUG) xer_fprint(stdout, &asn_DEF_MmsPdu, mmsPdu); /* Free ASN structure */ request->variableAccessSpecification.choice.listOfVariable.list.count = 0; free(request->variableAccessSpecification.choice.listOfVariable.list.array[0]); free(request->variableAccessSpecification.choice.listOfVariable.list.array); request->variableAccessSpecification.choice.listOfVariable.list.array = 0; request->listOfData.list.count = 0; deleteDataElement(request->listOfData.list.array[0]); free(request->listOfData.list.array); request->listOfData.list.array = 0; asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); return rval.encoded; }
int main( int ac, char **av) { char buf[ 1024]; /* Temp buffer */ ItevadMessage_t *itevadMsg = NULL; /* Type to decode */ asn_dec_rval_t rval; /* Decoder return value */ FILE *fp; /* Input file handler */ size_t size; /* Number of bytes read */ char *filename; /* Input file name */ /* Require a single filename argument */ if ( ac != 2) { fprintf( stderr, "Usage: %s <file.ber>\n", av[ 0]); exit(64); /* better, EX_USAGE */ } else { filename = av[ 1]; } /* Open input file as read-only binary */ fp = fopen( filename, "rb"); if ( !fp) { perror( filename); exit(66); /* better, EX_NOINPUT */ } /* Read up to the buffer size */ size = fread( buf, 1, sizeof( buf), fp); fclose( fp); if ( !size) { fprintf( stderr, "%s: Empty or broken\n", filename); exit(65); /* better, EX_DATAERR */ } /* Decode the input buffer as Itevad type */ rval = ber_decode( 0, &asn_DEF_ItevadMessage, (void **)&itevadMsg, buf, size); if ( rval.code != RC_OK) { fprintf( stderr, "%s: Broken ItevadMessage decoding at byte %ld\n", filename, (long)rval.consumed); exit(65); /* better, EX_DATAERR */ } /* Print the decoded Itevad type as XML */ xer_fprint( stdout, &asn_DEF_ItevadMessage, itevadMsg); /* Decoding finished successfully */ return 0; }