diff --git a/simics-workspace/modules/afdxES/Makefile b/simics-workspace/modules/afdxES/Makefile
index a0fb911..9d20e12 100644
--- a/simics-workspace/modules/afdxES/Makefile
+++ b/simics-workspace/modules/afdxES/Makefile
@@ -9,7 +9,8 @@ SRC_FILES = tomiddleware.c
 DML_FILES = afdxES.dml
 DMLC_FLAGS = -m -I$(SIMICS_WORKSPACE)/include

-MODULE_LDFLAGS = -lws2_32
+MODULE_CFLAGS = -I$(SIMICS_WORKSPACE)/modules/afdxES/inc/
+MODULE_LDFLAGS = $(SIMICS_WORKSPACE)\modules\afdxES\lib\AFDX_Card.lib -lws2_32

 SIMICS_API := 4.6
 THREAD_SAFE := yes
diff --git a/simics-workspace/modules/afdxES/hwa_aes_klib.h b/simics-workspace/modules/afdxES/hwa_aes_klib.h
deleted file mode 100644
index cc3cc62..0000000
--- a/simics-workspace/modules/afdxES/hwa_aes_klib.h
+++ /dev/null
@@ -1,425 +0,0 @@
-#ifndef _HWA_AES_KLIB_H_
-#define _HWA_AES_KLIB_H_
-
-#ifdef WIN32  /* For Windows */
-
-#ifdef _AFDX_EXPORT
-	#ifdef __cplusplus
-		#define _AFDX_DLL_EXPORT extern "C" __declspec(dllexport)
-	#else
-		#define _AFDX_DLL_EXPORT __declspec(dllexport)
-	#endif
-#else
-	#ifdef __cplusplus
-		#define _AFDX_DLL_EXPORT extern "C" __declspec(dllimport)
-	#else
-		#define _AFDX_DLL_EXPORT __declspec(dllimport)
-	#endif
-#endif
-
-#else  /* For VxWorks */
-
-#define _AFDX_DLL_EXPORT
-
-#endif
-
-/* Error Code */
-#define HWA_AES_OK							0
-#define HWA_AES_CARD_NOT_FOUND				-1
-#define HWA_AES_CARD_NOT_OPEN				-2
-#define HWA_AES_CARD_INVALID				-3
-#define HWA_AES_OPEN_FILE_ERR				-4
-#define HWA_AES_AFDX_615A_LOAD_MODE			-5
-#define HWA_AES_RESET_ERR					-6
-#define HWA_AES_XML_FILE_ERR				-7
-#define HWA_AES_PARAMETER_ERR				-8
-#define HWA_AES_SEM_ERR						-9
-#define HWA_AES_CHECK_DMA_TIMEOUT			-10
-#define HWA_AES_BUF_OVERFLOW				-11
-#define HWA_AES_ISR_ERR						-12
-#define HWA_AES_RECV_DATA_ERR				-13
-#define HWA_AES_NO_MEM						-14
-#define HWA_AES_INIT_ERR					-15
-#define HWA_AES_UNKNOWN_ERR					-16
-#define HWA_AES_PORT_EXIST                  -17
-#define HWA_AES_MSGQ_ERR                    -18
-#define HWA_AES_TASK_ERR        			-19
-#define HWA_AES_PHY_ERR          			-20
-#define HWA_AES_PHY_NO_LINK  				-21
-#define HWA_AES_LOAD_FPGA 					-22
-#define HWA_AES_LOAD_XML_FROM_FLASH_MAGICNUM	-23
-#define HWA_AES_LOAD_XML_FORM_FLASH 			-24
-#define HWA_AES_DMA_INIT_ERR 					-25
-#define HWA_AES_SET_PCI_ERR 					-26
-#define HWA_AES_ONLY_NORMAL_MODE 				-27
-#define HWA_AES_CARD_ALREADY_OPEN 				-28
-#define HWA_AES_CARD_CLOSE 						-29
-#define HWA_AES_UNINIT_ERR 						-30
-#define HWA_AES_OPEN_ERR 						-31
-#define HWA_AES_LOAD_XML 						-32
-#define HWA_AES_NOT_SUPPORT 					-33
-#define HWA_AES_CLOSE_ERR 						-34
-#define HWA_AES_PORT_BUSY 						-35
-#define HWA_AES_PORT_NOTFOUND 					-36
-#define HWA_AES_PORT_TOO_MANY					-37
-#define HWA_AES_PORT_DUPLICATE  				-38
-
-
-/*Monitor Mode*/
-#define HWA_AES_MONITOR_START_EXIST -130
-#define HWA_AES_FINISHED_FIND -131
-#define HWA_AES_ONLY_MONITOR_MODE -132
-
-#if 0
-/* MIB statistic : network statistic type */
-#define MIB_CRC_ERR_NUM					0
-#define MIB_SHORT_FRAME_ERR_NUM			1
-#define MIB_LONG_1518_FRAME_ERR_NUM			2
-#define MIB_RECV_FRAME_NUM				3
-#define MIB_RECV_FRAME_64TO127_NUM		4
-#define MIB_RECV_FRAME_128TO255_NUM		5
-#define MIB_RECV_FRAME_256TO511_NUM		6
-#define MIB_RECV_FRAME_512TO1023_NUM	7
-#define MIB_RECV_FRAME_1024TO1518_NUM	8
-#define MIB_RECV_FRAME_BYTES			9
-#define MIB_SEND_FRAME_NUM				10
-#define MIB_SEND_FRAME_64TO127_NUM		11
-#define MIB_SEND_FRAME_128TO255_NUM		12
-#define MIB_SEND_FRAME_256TO511_NUM		13
-#define MIB_SEND_FRAME_512TO1023_NUM	14
-#define MIB_SEND_FRAME_1024TO1518_NUM	15
-#define MIB_SEND_FRAME_BYTES			16
-
-#define MIB_RECV_FRAME_PRE_ERR_NUM 17
-#define MIB_RECV_FRAME_IPCHECKSUM_ERR_NUM 18
-#define MIB_LONG_2048_FRAME_ERR_NUM 19
-
-/*MIB statistic : rx type */
-#define MIB_RX_A_DISABLE_TO_FILTER_FRAME_NUM 0
-#define MIB_RX_B_DISABLE_TO_FILTER_FRAME_NUM 1
-#define MIB_RX_A_CRC_ERR_TO_FILTER_FRAME_NUM 2
-#define MIB_RX_B_CRC_ERR_TO_FILTER_FRAME_NUM 3
-#define MIB_RX_VL_ERR_TO_FILTER_FRAME_NUM 4
-#define MIB_RX_REDUND_ERR_TO_FILTER_FRAME_NUM 5
-#define MIB_RX_DSTUDP_ERR_TO_FILTER_FRAME_NUM 6
-#define MIB_RX_IP_CHECKSUM_ERR_TO_FILTER_FRAME_NUM 7
-#define MIB_RX_IP_LEN_ERR_TO_FILTER_FRAME_NUM 8
-#define MIB_RX_UDP_LEN_ERR_TO_FILTER_FRAME_NUM 9
-#define MIB_RX_IP_FRAGMENT_ERR_TO_FILTER_FRAME_NUM 10
-
-#else
-typedef enum{
-	MIB_TX_SEND_IP_TOTAL_NUM=0,
-	MIB_TX_SEND_UDP_TOTAL_NUM,
-	MIB_TX_SEND_ICMP_TOTAL_NUM,
-	MIB_TX_NR
-}HwaTxMibType;
-
-
-typedef enum{
-	MIB_RX_A_DISABLE_TO_FILTER_FRAME_NUM = 0,
-	MIB_RX_B_DISABLE_TO_FILTER_FRAME_NUM ,
-	MIB_RX_A_SN_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_B_SN_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_VL_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_REDUND_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_DSTPORT_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_IP_CHECKSUM_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_IP_LEN_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_UDP_LEN_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_IP_FRAGMENT_ERR_TO_FILTER_FRAME_NUM ,
-	MIB_RX_BUF_LOST_NUM,
-	MIB_RX_RECIVE_IP_PACKET_TOTAL_NUM,
-	MIB_RX_RECIVE_UDP_PACKET_TOTAL_NUM,
-	MIB_RX_RECIVE_ICMP_PACKET_TOTAL_NUM,
-	MIB_RX_RECIVE_ICMP_BACK_TOTAL_NUM,
-	MIB_RX_RECIVE_ICMP_BACK_LOST_TOTAL_NUM,
-	MIB_RX_RECIVE_ICMP_TLONG_FILTER_NUM,
-	MIB_RX_RECIVE_BUF_BACK_TOTAL_NUM,
-	MIB_RX_NR
-}HwaRxMibType;
-
-
-typedef enum{
-	MIB_CRC_ERR_NUM=0	,
-	MIB_SHORT_FRAME_ERR_NUM	,
-	MIB_LONG_1518_FRAME_ERR_NUM	,
-	MIB_RECV_FRAME_NUM,
-	MIB_RECV_FRAME_64TO127_NUM,
-	MIB_RECV_FRAME_128TO255_NUM,
-	MIB_RECV_FRAME_256TO511_NUM,
-	MIB_RECV_FRAME_512TO1023_NUM,
-	MIB_RECV_FRAME_1024TO1518_NUM,
-	MIB_RECV_FRAME_BYTES,
-	MIB_SEND_FRAME_NUM,
-	MIB_SEND_FRAME_64TO127_NUM,
-	MIB_SEND_FRAME_128TO255_NUM,
-	MIB_SEND_FRAME_256TO511_NUM,
-	MIB_SEND_FRAME_512TO1023_NUM,
-	MIB_SEND_FRAME_1024TO1518_NUM,
-	MIB_SEND_FRAME_BYTES,
-	MIB_RECV_FRAME_PRE_ERR_NUM ,
-	MIB_RECV_FRAME_IPCHECKSUM_ERR_NUM ,
-	MIB_LONG_2048_FRAME_ERR_NUM,
-	MIB_NET_NR
-}HwaNetMibType;
-#endif
-/* data struct */
-typedef enum  /* Afdx Card Work Mode */
-{
-	mode_normal = 0,
-	mode_test,
-	mode_monitor
-}HwaWorkMode;
-
-typedef enum	/* VL Direction*/
-{
-	vl_send	= 0,
-	vl_recv
-}HwaVlDirection;
-
-typedef enum /* Port Type */
-{
-	port_queue	= 0,
-	port_sample,
-	port_sap,
-	port_icmp,
-	port_type_nr
-}HwaPortType;
-
-typedef enum /* Net Type */
-{
-	net_a = 1,
-	net_b ,
-#if HWA_AES_8
-	net_c,
-	net_d,
-	net_e,
-	net_f,
-	net_g,
-	net_h,
-#endif
-	net_ab
-}HwaNetwork;
-
-typedef enum   /* Recv Mode (POLL or Interrupt)*/
-{
-	mode_poll =0,
-	mode_int
-}HwaRecvMode;
-
-typedef enum /* IRIGB Mode*/
-{
-	mode_slave =0 ,
-	mode_master
-}HwaIrigbMode;
-
-typedef enum /* OutPut Select (Rj45 or PMC J4)*/
-{
-	mode_j4=0,
-	mode_rj45
-}HwaOutputMode;
-
-typedef enum  /* Sampling Port Mode (Capture or No Capture)*/
-{
-	mode_nocapure=0,
-	mode_capture
-
-}HwaCaptureMode;
-
-typedef enum   /* Ip muliticast mode */
-{
-	mode_singlecast=0,
-	mode_multicast
-}HwaMulticastMode;
-
-typedef struct 		/* Card Info*/
-{
-	unsigned int vendor_id;
-	unsigned int device_id;
-	unsigned int bus_num;
-	unsigned int slot_num;
-	unsigned int func_num;
-	unsigned int hw_ver;
-	unsigned int work_mode;
-	char serial[16];
-}HwaCardInfo;
-
-typedef struct  /* packet stamp*/
-{
-	unsigned int day;
-	unsigned int hour;
-	unsigned int min;
-	unsigned int sec;
-	unsigned int ms;
-	unsigned int us;
-}HwaTime;
-
-typedef struct    /* recv time*/
-{
-	unsigned int time_low;   /* sec,min,us,ms*/
-	unsigned int time_high;  /* day ,hour*/
-}HwaRecvTime;
-
-typedef struct /* Monitor Mode ,resolved packet info*/
-{
-	unsigned char net;
-	int packet_len;
-	HwaRecvTime time;
-	unsigned int pre_error;
-	unsigned int ip_checksum_error;
-	unsigned int crc_error;
-	unsigned short startbit_pos;
-}HwaPackInfo;
-
-#define HWA_AES_IP_LEN 32
-typedef struct/*sap port information*/
-{
-	unsigned int local_udp;
-	unsigned int remote_udp;
-	char remote_ip[HWA_AES_IP_LEN];
-	HwaRecvTime time;
-	unsigned int network;
-	unsigned int valid;
-}HwaPktSrc;
-
-/* API */
-/* find all card,return the count of card */
-_AFDX_DLL_EXPORT int hwa_aes_find_card (void);
-
-/* free all card resource */
-_AFDX_DLL_EXPORT int hwa_aes_free_card(void);
-
-/* get card info */
-_AFDX_DLL_EXPORT int hwa_aes_get_card_info(int cardnum,HwaCardInfo *card_info);
-
-/* set addr remap ,only for vxworks */
-_AFDX_DLL_EXPORT int hwa_aes_set_addr_map(unsigned int (*func)());
-
-/* set card mode */
-_AFDX_DLL_EXPORT int hwa_aes_set_mode(int cardnum, unsigned int work_mode);
-
-/* open card */
-_AFDX_DLL_EXPORT int hwa_aes_open_card (int cardnum);
-
-/* close card */
-_AFDX_DLL_EXPORT int hwa_aes_close_card (int cardnum);
-
-/* set recv mode (poll or interrupt) */
-_AFDX_DLL_EXPORT int hwa_aes_set_recv_mode(int cardnum,int recv_mode);
-
-/* set irigb mode (slave or master)*/
-_AFDX_DLL_EXPORT int hwa_aes_set_irigb_mode(int cardnum,int irigb_mode);
-
-/* set card output(Rj45 or PMC j4)*/
-_AFDX_DLL_EXPORT int hwa_aes_set_output(int cardnum,int output);
-
-/*Set Caputure Mode*/
-_AFDX_DLL_EXPORT int hwa_aes_set_capture(int cardnum, int caputure);
-
-/*set user id*/
-_AFDX_DLL_EXPORT int hwa_aes_set_user_id(int cardnum,int user_id);
-
-/*load afdx xml*/
-_AFDX_DLL_EXPORT int hwa_aes_load_afdx_config (int cardnum, const char *cfgfilepath);
-
-/*Create VL and Port with Port_name*/
-_AFDX_DLL_EXPORT int hwa_aes_create_afdx_port (int cardnum,char *portName,unsigned int vlDirection,unsigned int *portId);
-
-/*Create VL*/
-_AFDX_DLL_EXPORT int hwa_aes_create_vl (int cardnum,unsigned int vlId,	unsigned int vlDirection,float bag,unsigned int skewMax,unsigned int vlNetwork,unsigned int *vlHandle);
-
-/*Create Port*/
-_AFDX_DLL_EXPORT int hwa_aes_create_port (int cardnum,unsigned int vlId,	unsigned int portType,unsigned short dstUDPPort,unsigned short srcUDPPort,unsigned int vlHandle,unsigned int *portId);
-
-/*Send Afdx Data*/
-_AFDX_DLL_EXPORT int hwa_aes_send (int cardnum,unsigned int portId,unsigned char *pPacket,int len);
-
-/*Receive Afdx Data*/
-_AFDX_DLL_EXPORT int hwa_aes_recv (int cardnum,	unsigned int portId,unsigned char *pPacket,int len,HwaRecvTime *time,unsigned int *network,unsigned int *valid);
-
-/*Receive Afdx Data*/
-_AFDX_DLL_EXPORT int hwa_aes_recv_ex(int cardnum, unsigned int hPort,unsigned char* pPacket, int len,int waittime,HwaPktSrc *pInfo);
-
-/*get port overflow info*/
-_AFDX_DLL_EXPORT int hwa_aes_mib_port_buf_overflow (int cardnum,unsigned int portId, int direction, unsigned int *value);
-
-/*get mib info*/
-_AFDX_DLL_EXPORT int hwa_aes_mib_net_state (int cardnum,HwaNetwork network, HwaNetMibType statType, unsigned int *value);
-
-/*get rx info*/
-_AFDX_DLL_EXPORT int hwa_aes_mib_rx_state (int cardnum,HwaRxMibType statType, unsigned int *value);
-
-/*get tx info*/
-_AFDX_DLL_EXPORT int hwa_aes_mib_tx_state (int cardnum,HwaTxMibType statType, unsigned int *value);
-
-/*clear mib info*/
-_AFDX_DLL_EXPORT int hwa_aes_mib_clear (int cardnum,unsigned int  mask);
-
-/*Close Port*/
-_AFDX_DLL_EXPORT int hwa_aes_close_port(int cardnum,unsigned int portId);
-
-/*resolve time*/
-_AFDX_DLL_EXPORT int hwa_aes_get_time(HwaRecvTime *time,HwaTime *localtime);
-
-/*get software version*/
-_AFDX_DLL_EXPORT int hwa_aes_get_soft_version(unsigned int *version);
-
-/*get hardware version*/
-_AFDX_DLL_EXPORT int hwa_aes_get_hard_version(int cardnum,unsigned int *version);
-
-/*get firmware version*/
-_AFDX_DLL_EXPORT int hwa_aes_get_firmware_version(int cardnum,unsigned int *version);
-
-/*check phy state*/
-_AFDX_DLL_EXPORT int hwa_aes_get_phystate(int cardnum,unsigned int *pState);
-
-/* Monitor Mode*/
-
-/*Monitor mode,start recv*/
-_AFDX_DLL_EXPORT int hwa_aes_monitor_start_recv(int cardnum);
-
-/*Monitor mode,stop recv*/
-_AFDX_DLL_EXPORT int hwa_aes_monitor_stop_recv(int cardnum);
-
-/*Monitor mode ,reslove packet*/
-_AFDX_DLL_EXPORT int hwa_aes_packet_find_next(unsigned char* pRecvBuff,int nSize,unsigned char ** ppPacket,HwaPackInfo* pPacketInfo,unsigned char** pCurPacketPos);
-
-/*creat a sap prot*/
-_AFDX_DLL_EXPORT int hwa_aes_create_sap_port(int cardNum,char *portName,unsigned int vlDir,unsigned int Udp,unsigned int subVl,unsigned int *portID);
-
-/*send AFDX data by a sap port*/
-_AFDX_DLL_EXPORT int hwa_aes_sap_send(int cardNum,unsigned int portId,unsigned char *buf,unsigned int bufLen, HwaPktSrc sapInfo);
-
-/*receive AFDX data from a sap port*/
-_AFDX_DLL_EXPORT int hwa_aes_sap_recv(int cardNum,unsigned int portId,unsigned char *buf,unsigned int bufLen,int waittime,HwaPktSrc *sapInfo);
-
-/*delete a sap port*/
-_AFDX_DLL_EXPORT int hwa_aes_close_sap_port(int cardNum,unsigned int portId);
-
-/*creat an ICMP port*/
-_AFDX_DLL_EXPORT int hwa_aes_create_icmp(int cardNum,char * portName,unsigned int vlDir,unsigned int * portID);
-
-/*send AFDX data by an ICMP port*/
-_AFDX_DLL_EXPORT int hwa_aes_icmp_send(int cardnum,unsigned int portId,unsigned char * buf,int bufLen,char *dstIp);
-/*recv AFDX data from an ICMP port */
-_AFDX_DLL_EXPORT int hwa_aes_icmp_recv(int cardnum,unsigned int portId,unsigned char * pPacket,int len,int waittime,HwaPktSrc *sapInfo);
-
-/*delete an ICMP port*/
-_AFDX_DLL_EXPORT int hwa_aes_close_icmp(int cardNum,unsigned int portId);
-
-/*read FPGA register*/
-_AFDX_DLL_EXPORT unsigned int hwa_aes_reg_read(int cardnum,unsigned int addr,int dev);
-
-/*write FPGA register*/
-_AFDX_DLL_EXPORT unsigned int hwa_aes_reg_write(int cardnum,unsigned int addr,unsigned int value,int dev);
-
-_AFDX_DLL_EXPORT  int hwa_aes_set_local_time(int cardnum,HwaTime *localtime);
-
-
-_AFDX_DLL_EXPORT  int hwa_aes_get_local_time(int cardnum,HwaTime *localtime);
-
-_AFDX_DLL_EXPORT void hwa_aes_get_soft_build_version(char *version);
-
-
-#endif
add afdxES card header
add afdxES card lib
add RDC
diff --git a/simics-workspace/modules/afdxES/tomiddleware.c b/simics-workspace/modules/afdxES/tomiddleware.c
index 5033e43..2f57c79 100644
--- a/simics-workspace/modules/afdxES/tomiddleware.c
+++ b/simics-workspace/modules/afdxES/tomiddleware.c
@@ -1,6 +1,17 @@
 #include "tomiddleware.h"

 SOCKET client_socket;
+#define MAX_RECV_PORTS 128
+#define MAX_SEND_PORTS 128
+#define MAX_PACK_LEN 8192
+
+SOCKET client_socket;
+static unsigned send_ports[MAX_SEND_PORTS];
+static unsigned recv_ports[MAX_RECV_PORTS];
+static int send_port_num;
+static int recv_port_num;
+static char send_port_name[30]="send_port_";
+static char recv_port_name[30]="recv_port_";

 int Init_664_Work_Mode(void) {
     WSADATA wsa;
@@ -86,3 +97,275 @@ int Recv_Mib_Info_From_664_Middleware(unsigned char *recvbuf, int size) {
     }
     return len;
 }
+
+const int analyse_cfg_cam_array_len = MAX_RECV_PORTS;
+struct analyse_cfg_cam analyse_cfg_cam_array[MAX_RECV_PORTS];
+
+const int analyse_cfg_ram_array_len = MAX_RECV_PORTS;
+struct analyse_cfg_ram analyse_cfg_ram_array[MAX_RECV_PORTS];
+
+const int transmit_cfg_ram_array_len = MAX_SEND_PORTS;
+struct transmit_cfg_ram transmit_cfg_ram_array[MAX_SEND_PORTS];
+
+const int scheduling_cfg_ram_array_len = MAX_SEND_PORTS;
+struct scheduling_cfg_ram scheduling_cfg_ram_array[ MAX_SEND_PORTS];
+
+const int fragment_cfg_ram_array_len = MAX_SEND_PORTS;
+struct fragment_cfg_ram fragment_cfg_ram_array[MAX_SEND_PORTS];
+
+const int rm_cfg_cam_array_len = MAX_VLS;
+struct rm_cfg_cam rm_cfg_cam_array[MAX_VLS];
+
+const int rm_cfg_ram_array_len = MAX_VLS;
+struct rm_cfg_ram rm_cfg_ram_array[MAX_VLS];
+
+void write_cfg_table(int type ,unsigned char *buf, int size) {
+
+	switch(type){
+		case ANALYSE_CFG_CAM:
+				memcpy(analyse_cfg_cam_array,buf,size);
+				break;
+		case ANALYSE_CFG_RAM:
+				memcpy(analyse_cfg_ram_array,buf,size);
+				break;
+		case TRANSMIT_CFG_RAM:
+				memcpy(transmit_cfg_ram_array,buf,size);
+				break;
+		case SCHEDULING_CFG_RAM:
+				memcpy(scheduling_cfg_ram_array,buf,size);
+				break;
+		case RM_CFG_CAM:
+				memcpy(rm_cfg_cam_array,buf,size);
+				break;
+		case RM_CFG_RAM:
+				memcpy(rm_cfg_ram_array,buf,size);
+				break;
+		case FRAGMENT_CFG_RAM:
+				memcpy(fragment_cfg_ram_array,buf,size);
+				break;
+		default:
+			break;
+	}
+}
+
+static int all_zeroes(char *buf, int buf_len)
+{
+	for (int i = 0; i < buf_len; i++)
+		if (buf[i] != 0)
+			return 0;
+	return 1;
+}
+
+static char* port_type_string(u16 port_type)
+{
+	switch (port_type) {
+	case 0:
+		return "Queue";
+	case 1:
+		return "Sample";
+	case 2:
+		return "SAP";
+	case 3:
+		return "ICMP";
+	default:
+		printf( "port_type_string(): unrecognized port type.\n");
+		return "";
+	}
+}
+
+static char* ab_enable_string(u32 enable_a, u32 enable_b)
+{
+	if (enable_a && enable_b)
+		return "AB";
+	else if (enable_a)
+		return "A";
+	else if (enable_b)
+		return "B";
+	else
+		printf( "ab_enable_string(): at least one of network a/b must be enabled.\n");
+	return "";
+}
+
+
+void send_port_string(FILE *fp) {
+	int i;
+	int j;
+	u64 tt;
+	for (i = 0; i < transmit_cfg_ram_array_len; i++) {
+		struct transmit_cfg_ram *ram = &transmit_cfg_ram_array[i];
+		if (all_zeroes((char *)ram, sizeof(*ram)))
+			continue;
+		send_port_num++;
+		sprintf(send_port_name,"send_port_%d",i);
+		fprintf(fp,"<AFDXPort ");
+		fprintf(fp,"BAG=\"%d\" ",scheduling_cfg_ram_array[ram->vl_index].bag / 1000);
+		fprintf(fp,"DirectionType=\"Send\" ");
+		fprintf(fp,"DstIP_2=\"%d\" ",ram->user_defined_id_h<<6|ram->user_defined_id_l>>8);
+		fprintf(fp,"DstIP_3=\"%d\" ",ram->user_defined_id_l & 0xff);
+		fprintf(fp,"DstIP_4=\"%d\" ",ram->dst_partition_id);
+		fprintf(fp,"DstUDP=\"%d\" ",ram->dest_udp_port);
+		fprintf(fp,"MaxFrameSize=\"%d\" ",fragment_cfg_ram_array[i].max_frame_length);
+		fprintf(fp,"MinFrameSize=\"%d\" ",ram->min_frame_length);
+		fprintf(fp,"Multicast=\"%s\" ",ram->ip_multicast? "Enable" : "Disable");
+		fprintf(fp,"PartitionID=\"%d\" ",ram->partition_id);
+		fprintf(fp,"PortName=\"%s\" ",send_port_name);
+		fprintf(fp,"PortNetwork=\"%s\" ",ab_enable_string(ram->interface_id & 1, ram->interface_id & 2));
+		fprintf(fp,"PortType=\"%s\" ", port_type_string(ram->port_type));
+		fprintf(fp,"SrcUDP=\"%d\" ",ram->source_udp_port);
+		fprintf(fp,"SubVL=\"%d\" ",ram->sub_vl_id);
+		fprintf(fp,"VL=\"%d\" ",ram->vl_id);
+		fprintf(fp,"VLNetwork=\"%s\" ",ab_enable_string(ram->interface_id & 1, ram->interface_id & 2));
+		fprintf(fp,"/>\n");
+	}
+}
+
+struct rm_cfg_ram* get_vl_conf(u16 vl_id)
+{
+	for (int i = 0; i < rm_cfg_cam_array_len; i++)
+		if (rm_cfg_cam_array[i].vl_id == vl_id)
+			return &rm_cfg_ram_array[rm_cfg_cam_array[i].address];
+	return NULL;
+}
+
+static unsigned ip_part(u32 ip, unsigned offset)
+{
+	return (unsigned)((unsigned char *)&ip)[offset - 1]; // NOTE: offset is 1-based.
+}
+
+void recv_port_string(FILE *fp) {
+	int i;
+	for (i = 0; i < analyse_cfg_cam_array_len; i++) {
+
+		struct analyse_cfg_cam *cam = &analyse_cfg_cam_array[i];
+		struct analyse_cfg_ram *ram = &analyse_cfg_ram_array[cam->address];
+		if (all_zeroes((char *)cam, sizeof(*cam)) || all_zeroes((char *)ram, sizeof(*ram)))
+			continue;
+
+		recv_port_num++;
+		struct rm_cfg_ram *vl_ram = get_vl_conf(cam->vl_id);
+		sprintf(recv_port_name,"recv_port_%d",i);
+		fprintf(fp,"<AFDXPort ");
+		fprintf(fp,"DirectionType=\"Recv\" ");
+		fprintf(fp,"DstIP_2=\"%d\" ",ip_part(cam->dest_ip, 3));
+		fprintf(fp,"DstIP_3=\"%d\" ",ip_part(cam->dest_ip, 2));
+		fprintf(fp,"DstIP_4=\"%d\" ",ip_part(cam->dest_ip, 1));
+		fprintf(fp,"DstUDP=\"%d\" ",cam->dest_udp);
+		fprintf(fp,"IntegralityCheckA=\"%s\" ",vl_ram->network_a_ic_enable? "Enable" : "Disable");
+		fprintf(fp,"IntegralityCheckB=\"%s\" ",vl_ram->network_b_ic_enable? "Enable" : "Disable");
+		fprintf(fp,"Multicast=\"%s\" ",cam->multicast_id? "Enable" : "Disable");
+		fprintf(fp,"PartitionID=\"%d\" ",ip_part(cam->dest_ip, 1));
+		fprintf(fp,"PortName=\"%s\" ",recv_port_name);
+		fprintf(fp,"PortNetwork=\"%s\" ",ab_enable_string(ram->network_a_enable, ram->network_b_enable));
+		fprintf(fp,"PortType=\"%s\" ",port_type_string(ram->port_type));
+		fprintf(fp,"Redund=\"%s\" ",vl_ram->rm_enable?  "Enable" : "Disable");
+		fprintf(fp,"SkewMax=\"%d\" ",vl_ram->skew_max);
+		fprintf(fp,"SrcUDP=\"0\" ");
+		fprintf(fp,"VL=\"%d\" ",cam->vl_id);
+		fprintf(fp,"VLNetwork=\"%s\" ",ab_enable_string(vl_ram->network_a_enable, vl_ram->network_b_enable));
+		fprintf(fp,"/>\n");
+	}
+}
+
+void LoadCfgTo664Middleware() {
+	FILE *fp;
+	fp = fopen("a664conf.xml","w+");
+	if(fp == NULL){
+		printf("open rx_mib.txt failed\n");
+	} else {
+		printf("open rx_mib.txt succeed\n");
+	}
+
+	fprintf(fp,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+	fprintf(fp,"<AFDXCard CreateTime=\"2011-12-27 13:39:29\" Company=\"Hwa Create\">\n");
+	fprintf(fp,"<AFDXNetwork Speed=\"100\">\n");
+//	fprintf(fp,"<AFDXEs UserDefinedID=\"%d\">\n",transmit_cfg_ram_array[0].user_defined_id_h<<14 | transmit_cfg_ram_array[0].user_defined_id_l);
+	fprintf(fp,"<AFDXEs UserDefinedID=\"%d\">\n",transmit_cfg_ram_array[0].user_defined_id);
+	send_port_string(fp);
+	recv_port_string(fp);
+	fprintf(fp,"</AFDXEs>\n");
+	fprintf(fp,"</AFDXNetwork>\n");
+	fprintf(fp,"</AFDXCard>\n");
+
+	fclose(fp);
+}
+
+int Init_664_Card(void) {
+	int cardnum;
+	int card_count;
+	int ret =0;
+	int i;
+
+
+	//find card
+	card_count = hwa_aes_find_card();
+	if (card_count <= 0) {
+		printf("No Card : %d\n", card_count);
+		hwa_aes_free_card();
+		getchar();
+		return -1;
+	}
+	//for test
+	cardnum = 0;
+
+	hwa_aes_set_mode(cardnum,mode_normal);
+
+	//open card
+	printf("Opening Card...\n");
+	if ((ret=hwa_aes_open_card(cardnum)) != HWA_AES_OK) {
+		printf("open failed\n");
+		getchar();
+		return ret;
+	}
+	printf ("open card OK!\n");
+
+	//load config
+	printf("load afdx config ...\n");
+	if( (ret=hwa_aes_load_afdx_config (cardnum, "a664conf.xml")) != HWA_AES_OK)	{
+		printf ("load afdx config failed with %d!\n",ret);
+		getchar();
+		return -4;
+	}
+	printf ("load afdx config OK!\n");
+
+	for (i=0; i < send_port_num; i++) {
+		sprintf(send_port_name,"send_port_%d",i);
+		if((ret=hwa_aes_create_afdx_port(cardnum,send_port_name,vl_send,send_ports+i)) != HWA_AES_OK) {
+			printf ("create send port error\n");
+			getchar();
+			if(i==0)
+				return 100;
+			return i;
+		}
+	}
+	for (i=0; i < recv_port_num; i++) {
+		sprintf(recv_port_name,"recv_port_%d",i);
+		if((ret=hwa_aes_create_afdx_port(cardnum,recv_port_name,vl_recv,recv_ports+i)) != HWA_AES_OK) {
+			printf ("create recv port error\n");
+			getchar();
+			return -8;
+		}
+	}
+
+	return 0;
+}
+
+int Recv_From_A664(int card_nr, int port_id, unsigned char *buf) {
+	HwaRecvTime time;
+	unsigned network;
+	unsigned valid;
+
+	int len = hwa_aes_recv(card_nr, recv_ports[port_id], buf, MAX_PACK_LEN, &time, &network, &valid);
+
+	return len;
+}
+
+int Send_To_A664(int card_nr, int port_id, unsigned char *buf, int len) {
+	int ret = hwa_aes_send (card_nr, send_ports[port_id], buf, len);
+
+	return ret;
+}
+
+int get_recv_port_num() {
+	return recv_port_num;
+}
+
diff --git a/simics-workspace/modules/afdxES/tomiddleware.h b/simics-workspace/modules/afdxES/tomiddleware.h
index 4d82b19..896f819 100644
--- a/simics-workspace/modules/afdxES/tomiddleware.h
+++ b/simics-workspace/modules/afdxES/tomiddleware.h
@@ -1,5 +1,6 @@
 #ifndef __TOMIDDLEWARE_H__
 #define __TOMIDDLEWARE_H__
+#pragma once

 #include <stdio.h>
 #include <string.h>
@@ -7,7 +8,97 @@
 #include <errno.h>
 #include <unistd.h>
 #include <WINSOCK2.H>
+#include "hwa_aes_klib.h"

+typedef unsigned long long u64;
+typedef unsigned int u32;
+typedef unsigned short u16;
+
+#define  MAX_RECV_PORTS  128
+#define MAX_SEND_PORTS  128
+#define MAX_VLS  128
+
+struct analyse_cfg_cam {
+	u32 address;
+
+	u32 multicast_id : 1;
+	u32 icmp_type_id : 1;
+	u32 __reserved : 30;
+
+	u32 dest_ip;
+
+	u16 dest_udp;
+	u16 vl_id;
+};
+
+struct analyse_cfg_ram {
+	u16 port_type : 2;
+	u16 network_a_enable : 1;
+	u16 network_b_enable : 1;
+	u16 __reserved : 12;
+};
+
+struct transmit_cfg_ram {
+	u32 dst_partition_id;
+	u32 user_defined_id_l;
+	u32 user_defined_id_h;
+	u32 private_ip;
+
+	u32 vl_id ;
+	u32 vl_index;
+	u32 ip_multicast;
+	u32 min_frame_length;
+	u32 port_type;
+
+	u32 partition_id;
+	u32 interface_id;
+	u32 protocol_id;
+	u32 user_defined_id;
+
+	u32 sub_vl_id;
+	u32 dest_udp_port;
+	u32 source_udp_port;
+};
+
+struct scheduling_cfg_ram {
+	u32 bag;
+};
+
+struct rm_cfg_cam {
+	u32 address;
+	u16 vl_id;
+};
+
+struct rm_cfg_ram {
+	u32 network_a_enable : 1;
+	u32 network_b_enable : 1;
+	u32 network_a_ic_enable : 1;
+	u32 network_b_ic_enable : 1;
+	u32 rm_enable : 1;
+	u32 skew_max : 21;
+	u32 vl_enable : 1;
+	u32 __reserved : 5;
+};
+
+struct fragment_cfg_ram {
+	u16 max_frame_length;
+};
+
+enum netpack_type_t {
+	ANALYSE_CFG_CAM = 0,
+	ANALYSE_CFG_RAM = 1,
+	TRANSMIT_CFG_RAM = 2,
+	SCHEDULING_CFG_RAM = 3,
+	RM_CFG_CAM = 4,
+	RM_CFG_RAM = 5,
+	FRAGMENT_CFG_RAM = 6,
+	PACKET_SEND = 7,
+	PACKET_RECV = 8, // the only pack from midware to simulator.
+	DO_LOAD_CONF = 9,
+	MAC_MIB = 10,
+	RX_MIB = 11,
+	TX_MIB = 12
+};

 extern int Init_664_Work_Mode(void);
 extern int Send_To_664_Middleware(unsigned char *recvbuf, int size);
diff --git a/simics-workspace/modules/ARINC-429Mode/ARINC_429Mode.py b/simics-workspace/modules/ARINC-429Mode/ARINC_429Mode.py
old mode 100644
new mode 100755
index c4d67ac..3dece5c
--- a/simics-workspace/modules/ARINC-429Mode/ARINC_429Mode.py
+++ b/simics-workspace/modules/ARINC-429Mode/ARINC_429Mode.py
@@ -1,40 +1,41 @@
-# MODULE: ARINC-429Mode
-# COMPONENT: ARINC_429Mode
-
-# empty_component.py - sample code for a Simics configuration component
-# Use this file as a skeleton for your own component implementations.
-
-from comp import *
-
-class ARINC_429Mode(StandardConnectorComponent):
-    """The empty component class."""
-    _class_desc = "empty component"
-    _help_categories = ()
-
-    def setup(self):
-        StandardConnectorComponent.setup(self)
-        if not self.instantiated.val:
-            self.add_objects()
-
-    def add_objects(self):
-        # TODO: replace the example pci-bus connector with relevant connectors
-        self.add_connector('pci', PciBusUpConnector(0, 'sample_dev'))
-        # TODO: create relevant conf_objects and set initial attributes in them
-        clock = self.add_pre_obj('clock', 'clock', freq_mhz = 10)
-        sample = self.add_pre_obj('sample_dev', 'sample_pci_device')
-        sample.int_attr = 4711
-
-    # TODO: replace attribute with relevant attributes
-    class attribute0(ConfigAttribute):
-        """attribute0"""
-        attrtype = "i"
-        def _initialize(self):
-            self.val = 4711
-        def getter(self):
-            return self.val
-        def setter(self, val):
-            self.val = val
-
-    # TODO: replace attribute with relevant attributes
-    class attribute1(SimpleConfigAttribute(None, 'i')):
-        """attribute1"""
+# MODULE: ARINC_429Mode
+# COMPONENT: ARINC_429Mode
+
+# empty_component.py - sample code for a Simics configuration component
+# Use this file as a skeleton for your own component implementations.
+
+from comp import *
+
+class ARINC_429Mode(StandardConnectorComponent):
+    """The empty component class."""
+    _class_desc = "empty component"
+    _help_categories = ()
+
+    def setup(self):
+        self.add_connector('pci_bus', PciBusUpConnector(0, 'afdxES'))
+        afdxES = self.add_pre_obj('afdxES', 'afdxES')
+        afdxES2 = self.add_pre_obj('afdxES2', 'afdxES2')
+        RDC = self.add_pre_obj('RDC', 'RDC')
+        afdxES2.RDC = RDC
+        RDC.ARINC664_2 = afdxES2
+        RDC.LoadCfg = afdxES2
+        afdxES.phyA = afdxES2
+        afdxES2.phyA = afdxES
+        afdxES.phyB = afdxES2
+        afdxES2.phyB = afdxES
+
+    def add_objects(self):
+        self.add_connector('pci_bus', PciBusUpConnector(0, 'afdxES'))
+        afdxES = self.add_pre_obj('afdxES', 'afdxES')
+
+    class component_connector(Interface):
+        def get_check_data(self, cnt):
+            return []
+        def get_connect_data(self, cnt):
+            return [[[0, self._up.get_slot('afdxES')]]]
+        def check(self, cnt, attr):
+            return True
+        def connect(self, cnt, attr):
+            self._up.get_slot('afdxES').pci_bus = attr[1]
+        def disconnect(self, cnt):
+            self._up.get_slot('afdxES').pci_bus = None
\ No newline at end of file
diff --git a/simics-workspace/modules/ARINC-664Mode/ARINC_664Mode.py b/simics-workspace/modules/ARINC-664Mode/ARINC_664Mode.py
old mode 100644
new mode 100755
index 912391d..430dd9b
--- a/simics-workspace/modules/ARINC-664Mode/ARINC_664Mode.py
+++ b/simics-workspace/modules/ARINC-664Mode/ARINC_664Mode.py
@@ -1,40 +1,34 @@
-# MODULE: ARINC-664Mode
-# COMPONENT: ARINC_664Mode
-
-# empty_component.py - sample code for a Simics configuration component
-# Use this file as a skeleton for your own component implementations.
-
-from comp import *
-
-class ARINC_664Mode(StandardConnectorComponent):
-    """The empty component class."""
-    _class_desc = "empty component"
-    _help_categories = ()
-
-    def setup(self):
-        StandardConnectorComponent.setup(self)
-        if not self.instantiated.val:
-            self.add_objects()
-
-    def add_objects(self):
-        # TODO: replace the example pci-bus connector with relevant connectors
-        self.add_connector('pci', PciBusUpConnector(0, 'sample_dev'))
-        # TODO: create relevant conf_objects and set initial attributes in them
-        clock = self.add_pre_obj('clock', 'clock', freq_mhz = 10)
-        sample = self.add_pre_obj('sample_dev', 'sample_pci_device')
-        sample.int_attr = 4711
-
-    # TODO: replace attribute with relevant attributes
-    class attribute0(ConfigAttribute):
-        """attribute0"""
-        attrtype = "i"
-        def _initialize(self):
-            self.val = 4711
-        def getter(self):
-            return self.val
-        def setter(self, val):
-            self.val = val
-
-    # TODO: replace attribute with relevant attributes
-    class attribute1(SimpleConfigAttribute(None, 'i')):
-        """attribute1"""
+# MODULE: ARINC_664Mode
+# COMPONENT: ARINC_664Mode
+
+# empty_component.py - sample code for a Simics configuration component
+# Use this file as a skeleton for your own component implementations.
+
+from comp import *
+
+class ARINC_664Mode(StandardConnectorComponent):
+    """The empty component class."""
+    _class_desc = "empty component"
+    _help_categories = ()
+
+    def setup(self):
+        StandardConnectorComponent.setup(self)
+        if not self.instantiated.val:
+            self.add_objects()
+
+    def add_objects(self):
+        self.add_connector('pci_bus', PciBusUpConnector(0, 'afdxES'))
+        afdxES = self.add_pre_obj('afdxES', 'afdxES')
+        afdxES.middleware_mode = 1
+
+    class component_connector(Interface):
+        def get_check_data(self, cnt):
+            return []
+        def get_connect_data(self, cnt):
+            return [[[0, self._up.get_slot('afdxES')]]]
+        def check(self, cnt, attr):
+            return True
+        def connect(self, cnt, attr):
+            self._up.get_slot('afdxES').pci_bus = attr[1]
+        def disconnect(self, cnt):
+            self._up.get_slot('afdxES').pci_bus = None
del myhello
del rtc_module