Protokollsachen: Structs aus C++ übernehmen?

BeaTBoxX

Erfahrenes Mitglied
Moin zusammen,

ich haeng grad an einem Projekt wo ich mit dem Protokoll Q3 (Mobilfunk.. evtl sagts wem was) mit einer .. naja sagen wir "Kiste" im weitesten Sinne kommunizieren muss.

Dafür wurde schon mal was gemacht.. allerdings in C++.

Dort wurden z.b. für den Login Strukturen angelegt.

Beispiel:

Code:
struct APDU_Header_HEX_CC 
{  
  /*** TPTK HEADER = 4 Bytes ***/
  BYTE  TPTK_Version;                           /* TPTK Version */
  BYTE  TPTK_Reserved;                          /* TPTK Reserved */
  WORD  TPTK_Length;                           /* TPTK Length */  

  /*** COTP HEADER = 3 Bytes ***/
  BYTE  COTP_Length;                           /* TPTK Version */
  BYTE  COTP_PDU_Type;                          /* TPTK Reserved */
  BYTE  COTP_TPDU_Nr;                           /* TPTK Length */ 

  /*** SPDU HEADER ***/
  BYTE    SPDU_Type;                          /* Byte for SPDU Type */
  BYTE    SPDU_Length;                        /* Byte for SPDU Length */
  DWORD   SPDU_Conn_Acpt_Item1;
  DWORD   SPDU_Conn_Acpt_Item2;
  DWORD   SPDU_Session_Requirement;

  /*** Calling Session Selector ***/
  BYTE    SPDU_Calling_SSEL_Type;
  BYTE    SPDU_Calling_SSEL_Length;
  BYTE    SPDU_Calling_SSEL_Val1;
  BYTE    SPDU_Calling_SSEL_Val2;
  BYTE    SPDU_Calling_SSEL_Val3;
  BYTE    SPDU_Calling_SSEL_Val4;
  BYTE    SPDU_Calling_SSEL_Val5;

  /*** Called Session Selector ***/
  BYTE    SPDU_Called_SSEL_Type;
  BYTE    SPDU_Called_SSEL_Length;
  BYTE    SPDU_Called_SSEL_Val1;
  BYTE    SPDU_Called_SSEL_Val2;
  BYTE    SPDU_Called_SSEL_Val3;

  /*** Session User Data ***/
  BYTE    SPDU_Session_User_Data;
  BYTE    SPDU_Session_Data_Length;

  /*** Presentation Protocol ***/
  WORD    SPDU_PRES_Resp;    
  BYTE    SPDU_PRES_Resp_Add;

  WORD    SPDU_PRES_CPType;
  BYTE    SPDU_PRES_ModeSel_1;
  BYTE    SPDU_PRES_ModeSel_2;
  BYTE    SPDU_PRES_ModeSel_3;

  WORD    SPDU_PRES_Mode_Parameters;
  BYTE    SPDU_PRES_Mode_Parameters_Add;
  BYTE    SPDU_PRES_Mode_Parameters_Add1;
  WORD    SPDU_PRES_Mode_Parameters_Add2;
  BYTE    SPDU_PRES_Protocol_Version;

  //Result-definition-list
  BYTE    SPDU_PRES_Context_Def_List_Init;
  BYTE    SPDU_PRES_Context_Def_List_Init_Add; // size of definiton list

  // first item acceptance
  BYTE    SPDU_PRES_Context_Def_List_Item_Init;
  BYTE    SPDU_PRES_Context_Def_List_Item_Init_Add;
  WORD    SPDU_PRES_Context_Def_List_Result;
  BYTE    SPDU_PRES_Context_Def_List_Result_Add;   
  DWORD   SPDU_PRES_Context_Def_List_Result_TSN; 

  // second item acceptance
  BYTE    SPDU_PRES_Context_Def_List_Item_Init_Data;
  BYTE    SPDU_PRES_Context_Def_List_Item_Init_Add_Data;
  WORD    SPDU_PRES_Context_Def_List_Result_Data;
  BYTE    SPDU_PRES_Context_Def_List_Result_Add_Data;   
  DWORD   SPDU_PRES_Context_Def_List_Result_TSN_Data;

  // User Data
  DWORD   SPDU_PRES_UserData_Version_Init;
  WORD    SPDU_PRES_Context_ID_Init;
  BYTE    SPDU_PRES_Context_ID_Value;
  WORD    SPDU_PRES_Data_Value;

  /*** ACSE ****/
  WORD    ACSE_Response_Value;

  // padding
  WORD    ACSE_Response_Padding_Init;
  BYTE    ACSE_Response_Padding_Value;

  // protocol version
  BYTE    ACSE_Response_Protocol_Version; 

  // as0 context name
  DWORD   ACSE_Response_as0_Context_Name_Init;
  DWORD   ACSE_Response_as0_Context_Name_Value;

  // result of ap title
  DWORD   ACSE_Response_APTitle_Result_Init;
  BYTE    ACSE_Response_APTitle_Result_Value; 

  // result soure diagnostic
  DWORD   ACSE_Response_Result_Diagnostic_Init;
  WORD    ACSE_Response_Service_User_Init;
  BYTE    ACSE_Response_Service_User_Value;

  // user information
  WORD    ACSE_Response_User_Information_Init;
  WORD    ACSE_Response_User_Information_Item_Init;  
  WORD    ACSE_Response_User_Information_Item_Direct_Ref_Init;
  WORD    ACSE_Response_User_Information_Item_Direct_Ref_Value;
  WORD    ACSE_Response_User_Information_Item_Indirect_Ref_Init;
  BYTE    ACSE_Response_User_Information_Item_Indirect_Ref_Value;  
  WORD    ACSE_Response_User_Information_Item_Single_ASN_Type;

  /*** CMIP ***/
  DWORD   CMIP_Response_Init;
  BYTE    CMIP_Response_Padding;
  BYTE    CMIP_Response_Protocol_Version;
  WORD    CMIP_Response_Functional_Unit_Init;
  WORD    CMIP_Response_Functional_Unit_Value;

} SPDU_CC;

Frage nun:

Wie realisiert man sowas sinnvoll in C# ?

Ich mein byte gibt es ja aber word, dword ... ?!

Hab schon bissl nachgelesen: Generell gibt es ja in c# immernoch structs. Macht es mehr sinn für sowas ne Klasse zu schreiben?
Wie realisier ich so Datenschnipsel die WORD oder DWORD waren?

Sonstwelche Tips für solch eine Protokollfummelei? Hab noch nicht so wirklich plan, was ich da tu %)
Ich hoff mal das Subforum is ok ;)

Vielen Dank!

Gruß
Frank
 
Zuletzt bearbeitet:
Such auch mal unter dem Stichwort P/Invoke. Da geht es eigentlich darum, externe Funktionen aus DLLs zu importieren (managed/unmanaged code), aber in diesem Zusammenhang werden auch Typentsprechungen genannt (so ist z.B. ein LPTCSTR in C# ein IntPtr). In der C#-Hilfe gibt es ebenfalls einige Übersichtstabellen dazu, irgendwo im Zusammenhang mit dem Stichwort DllImport.
 
Zurück