00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _CACONTROLCHANNELDISPATCHER_H_HEADER_
00030 #define _CACONTROLCHANNELDISPATCHER_H_HEADER_
00031 #include "CAQueue.hpp"
00032 class CAAbstractControlChannel;
00033
00037 class CAControlChannelDispatcher
00038 {
00039 public:
00044 CAControlChannelDispatcher(CAQueue* pSendQueue,UINT8* keyRecv,UINT8* keySent)
00045 {
00046 m_pSendQueue=pSendQueue;
00047 m_pQueueEntry=new tQueueEntry;
00048 m_pMixPacket=&m_pQueueEntry->packet;
00049 m_arControlChannels=new CAAbstractControlChannel*[256];
00050 memset(m_arControlChannels,0,256*sizeof(CAAbstractControlChannel*));
00051 m_pcsSendMsg=new CAMutex();
00052 m_pcsRegisterChannel=new CAMutex();
00053 m_pcsEnc=new CAMutex();
00054 m_pcsDec=new CAMutex();
00055 m_nEncMsgCounter=0;
00056 m_pEncMsgIV=new UINT8[12];
00057 memset(m_pEncMsgIV,0,12);
00058 m_nDecMsgCounter=0;
00059 m_pDecMsgIV=new UINT8[12];
00060 memset(m_pDecMsgIV,0,12);
00061 if(keySent!=NULL)
00062 {
00063 m_pGCMCtxEnc=new gcm_ctx_64k;
00064 m_pGCMCtxDec=new gcm_ctx_64k;
00065 gcm_init_64k(m_pGCMCtxEnc,keySent,128);
00066 gcm_init_64k(m_pGCMCtxDec,keyRecv,128);
00067 }
00068 else
00069 {
00070 m_pGCMCtxEnc=NULL;
00071 m_pGCMCtxDec=NULL;
00072 }
00073 }
00074
00075 ~CAControlChannelDispatcher()
00076 {
00077 delete m_pcsSendMsg;
00078 m_pcsSendMsg = NULL;
00079 delete m_pcsRegisterChannel;
00080 m_pcsRegisterChannel = NULL;
00081 delete[] m_arControlChannels;
00082 m_arControlChannels = NULL;
00083 delete m_pQueueEntry;
00084 m_pQueueEntry = NULL;
00085 if(m_pGCMCtxEnc!=NULL)
00086 delete m_pGCMCtxEnc;
00087 if(m_pGCMCtxDec!=NULL)
00088 delete m_pGCMCtxDec;
00089 delete []m_pEncMsgIV;
00090 delete m_pcsEnc;
00091 delete []m_pDecMsgIV;
00092 delete m_pcsDec;
00093 }
00094
00095 void deleteAllControlChannels(void);
00096
00098 SINT32 registerControlChannel(CAAbstractControlChannel* pControlChannel);
00099 SINT32 removeControlChannel(UINT32 id);
00100
00101 bool proccessMixPacket(const MIXPACKET* pPacket);
00102 SINT32 sendMessages(UINT32 id,const UINT8* msg,UINT32 msglen);
00103
00108 SINT32 encryptMessage(const UINT8* in,UINT32 inlen, UINT8* out,UINT32* outlen);
00113 SINT32 decryptMessage(const UINT8* in,UINT32 inlen, UINT8* out,UINT32* outlen);
00115 bool isKeySet()
00116 {
00117 return m_pGCMCtxEnc!=NULL;
00118 }
00119
00120 private:
00121 CAQueue* m_pSendQueue;
00122 MIXPACKET* m_pMixPacket;
00123 CAAbstractControlChannel** m_arControlChannels;
00124 tQueueEntry* m_pQueueEntry;
00125 CAMutex* m_pcsSendMsg;
00126 CAMutex* m_pcsRegisterChannel;
00127 CAMutex* m_pcsEnc;
00128 CAMutex* m_pcsDec;
00129
00130 gcm_ctx_64k* m_pGCMCtxEnc;
00131 gcm_ctx_64k* m_pGCMCtxDec;
00132 UINT32 m_nEncMsgCounter;
00133 UINT8* m_pEncMsgIV;
00134 UINT32 m_nDecMsgCounter;
00135 UINT8* m_pDecMsgIV;
00136 };
00137 #endif