我使用了libosmo-asn1-map中的C代码来获得GSM_-MAP协议的实现。然后我试着编码一个
“发送身份验证信息”消息。如3GPP TS 29.002中所述,此消息包含一些必需部分(如“imsi”)和一些可选部分(如“requestingNodeType”)。
/* SendAuthenticationInfoArg */
typedef struct SendAuthenticationInfoArg {
IMSI_t imsi;
NumberOfRequestedVectors_t numberOfRequestedVectors;
NULL_t *segmentationProhibited /* OPTIONAL */;
NULL_t *immediateResponsePreferred /* OPTIONAL */;
struct Re_synchronisationInfo *re_synchronisationInfo /* OPTIONAL */;
struct ExtensionContainer *extensionContainer /* OPTIONAL */;
/*
* This type is extensible,
* possible extensions are below.
*/
RequestingNodeType_t *requestingNodeType /* OPTIONAL */;
PLMN_Id_t *requestingPLMN_Id /* OPTIONAL */;
NumberOfRequestedVectors_t *numberOfRequestedAdditional_Vectors /* OPTIONAL */;
NULL_t *additionalVectorsAreForEPS /* OPTIONAL */;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} SendAuthenticationInfoArg_t;
我使用了下面的C代码,它的灵感来自osmo-tcap-map项目。
SendAuthenticationInfoArg_t ula;
memset(&ula, 0, sizeof(ula));
ASN1Common::OCTET_STRING_fromRevVal(&ula.imsi, 202015604083166);
ula.requestingNodeType = 0;
ula.numberOfRequestedVectors = 5;
xer_fprint(stdout, &asn_DEF_SendAuthenticationInfoArg, &ula);
但是,当“requestingNodeType”已初始化时,XER输出中没有可选部分:
<SendAuthenticationInfoArg>
<imsi>02 02 51 06 04 38 61 F6</imsi>
<numberOfRequestedVectors>5</numberOfRequestedVectors>
</SendAuthenticationInfoArg>
如何启用可选部分(即在消息中添加“requestingNodeType”)?
最佳答案
requestingNodeType
和numberOfRequestedVectors
都是指针
RequestingNodeType_t *requestingNodeType /* OPTIONAL */;
PLMN_Id_t *requestingPLMN_Id /* OPTIONAL */;
NumberOfRequestedVectors_t *numberOfRequestedAdditional_Vectors /* OPTIONAL */;
NULL_t *additionalVectorsAreForEPS /* OPTIONAL */;
所以你首先需要分配它们,应该是
ula.requestingNodeType = malloc(sizeof(RequestingNodeType_t));
asn_long2INTEGER(ula.requestingNodeType, RequestingNodeType_vlr);
RequestingNodeType_t
是typedef'd asENUMERATED_t
即typedef'd asINTEGER_t
这就是为什么我们不能直接赋值,而是使用asn_long2INTEGER
ula.numberOfRequestedVectors = malloc(sizeof(NumberOfRequestedVectors_t));
*ula.numberOfRequestedVectors = 5;
NumberOfRequestedVectors_t
是typedef'd aslong
所以这里我们可以直接赋值