Пример #1
0
ExtendedFrame::ExtendedFrame(const APDU& apdu)
{
	m_frame_len = 7 + apdu.GetApduLen() + 1;
	m_frame_mem = new UCHAR[m_frame_len];
	memset(m_frame_mem, 0, m_frame_len);

	// 设置控制字. 
	UCHAR& ctrl_code = m_frame_mem[0];
	ctrl_code &= 0x7F;   // 第一位置0就是扩展帧. 
	ctrl_code |= 0x20;   // 非重复的Frame. 
	ctrl_code |= 0x10;   // 数据帧. 
	UCHAR priority = apdu.GetPriority();
	priority <<= 2;
	ctrl_code |= priority;  // 设优先级. 

	// 设置扩展字. 
	UCHAR& ctrle_code = m_frame_mem[1];
	if ( apdu.GetAddrType() )
	{
		ctrle_code |= 0x80;
	}
	ctrle_code |= 0x70;  // Hop数写死为7.

	// 下面设源地址. 
	const UCHAR* hostaddr = apdu.GetHostAddr();
	m_frame_mem[2] = hostaddr[0];
	m_frame_mem[3] = hostaddr[1];

	// 下面设目标地址.  
	const UCHAR* peeraddr = apdu.GetPeerAddr();
	m_frame_mem[4] = peeraddr[0];
	m_frame_mem[5] = peeraddr[1];

	// 设置长度. 
	m_frame_mem[6] = apdu.GetApduLen();

	// 把APDU放入. 
	memcpy(m_frame_mem + 7, apdu.GetApduMem(), apdu.GetApduLen());

	// 算checksum. 
	m_frame_mem[m_frame_len-1] = xor_check_sum(m_frame_mem, m_frame_len-1);
}
Пример #2
0
StandardFrame::StandardFrame(const APDU& apdu)
{
	m_frame_len = 6 + apdu.GetApduLen() + 1;
	m_frame_mem = new UCHAR[m_frame_len];
	memset(m_frame_mem, 0, m_frame_len);

	// 设置控制字. 
	UCHAR& ctrl_code = m_frame_mem[0];
	ctrl_code |= 0x80;   // 第一位置一就是标准帧. 
	ctrl_code |= 0x20;   // 非重复的Frame. 
	ctrl_code |= 0x10;   // 数据帧. 
	UCHAR priority = apdu.GetPriority();
	priority <<= 2;
	ctrl_code |= priority;  // 设优先级. 

	// 下面设源地址.  
	const UCHAR* hostaddr = apdu.GetHostAddr();
	m_frame_mem[1] = hostaddr[0];
	m_frame_mem[2] = hostaddr[1];

	// 下面设目标地址.  
	const UCHAR* peeraddr = apdu.GetPeerAddr();
	m_frame_mem[3] = peeraddr[0];
	m_frame_mem[4] = peeraddr[1];

	// 设置八位组5. 
	UCHAR& octec5 = m_frame_mem[5];
	if ( apdu.GetAddrType() ) // 单个地址时返回 0. 标准组地组时返回 1
	{
		octec5 |= 0x80;
	}
	octec5 |= 0x70;  // hop数被写死成7.
	octec5 |= apdu.GetApduLen();

	// 把APDU放入.
	memcpy(m_frame_mem + 6, apdu.GetApduMem(), apdu.GetApduLen());

	// 算checksum
	m_frame_mem[m_frame_len-1] = xor_check_sum(m_frame_mem, m_frame_len-1);
}