void JIG_Task(void)
{
	static int bytes_out = 0, bytes_in = 0;

        Endpoint_SelectEndpoint(2);
        if (Endpoint_IsReadWriteAllowed())
        {
		Endpoint_Discard_Stream(8, NO_STREAM_CALLBACK);
                Endpoint_ClearOUT();
		bytes_out += 8;
		if (bytes_out >= 64) {
			state = p5_challenged;
			expire = 50; // was 90
		}
	}

        Endpoint_SelectEndpoint(1);
        if (Endpoint_IsReadWriteAllowed() && state == p5_challenged && expire == 0) 
	{
		if (bytes_in < 64) {
			Endpoint_Write_PStream_LE(&jig_response[bytes_in], 8, NO_STREAM_CALLBACK);
			Endpoint_ClearIN();
			bytes_in += 8;
			if (bytes_in >= 64) {
				state = p5_responded;
				expire = 15;
			}
		}
	}
}
示例#2
0
uint8_t CDC_Device_SendString_P(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
                              const char* const String)
{
	if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
	  return ENDPOINT_RWSTREAM_DeviceDisconnected;

	Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address);
	return Endpoint_Write_PStream_LE(String, strlen_P(String), NULL);
}
示例#3
0
uint8_t CDC_Device_SendData_P(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
                            const void* const Buffer,
                            const uint16_t Length)
{
	if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
	  return ENDPOINT_RWSTREAM_DeviceDisconnected;

	Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address);
	return Endpoint_Write_PStream_LE(Buffer, Length, NULL);
}
示例#4
0
	void 				JIG_Task								(void)					{
	 static int bytes_out = 0, bytes_in = 0;
     Endpoint_SelectEndpoint(2);
     if (Endpoint_IsReadWriteAllowed()) {
		Endpoint_Read_Stream_LE  (&jig_challenge_res[bytes_out], 8, NO_STREAM_CALLBACK) ;		
        Endpoint_ClearOUT();
		bytes_out += 8;
		if (bytes_out >= 64) {			
			//prepare the response (by guess?)
			jig_challenge_res[1]--;
			jig_challenge_res[3]++;
			jig_challenge_res[6]++;
			HMACBlock(&jig_challenge_res[CHALLENGE_INDEX],20);
			
			USB_USBTask(); //just in case
			HMACDone();
			jig_challenge_res[7] = jig_id[0];
			jig_challenge_res[8] = jig_id[1];
			int i;
			for( i = 0; i < 20; i++)
				jig_challenge_res[9+i] = hmacdigest[i];
			state = p5_challenged;
			expire = 50; // was 90
		}
	 }
     Endpoint_SelectEndpoint(1);
     if (Endpoint_IsReadWriteAllowed() && state == p5_challenged && expire == 0) {
		if ( bytes_in < 64) {
			Endpoint_Write_PStream_LE(&jig_challenge_res[bytes_in], 8, NO_STREAM_CALLBACK);
			Endpoint_ClearIN();
			bytes_in += 8;
			if ( bytes_in >= 64) {
				state = p5_responded;
				expire = 50;
			}
		}
	 }
	}