-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathPacket.c
58 lines (44 loc) · 1.16 KB
/
Packet.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Type.h"
#include "Protocol.h"
#include "Packet.h"
static BOOL BuildPacket(UINT8 *out, UINT8 maxLen, UINT8 *pLen, UINT8 id, const UINT8 *dat, UINT8 size)
{
UINT8 index;
UINT8 i;
UINT8 sum;
if (size + 2 > maxLen)
{
return FALSE;
}
index = 0;
out[index++] = id;
sum = id;
for (i = 0; i < size; i++)
{
out[index++] = *dat;
sum ^= *dat;
dat++;
}
out[index++] = sum;
if (pLen != NULL)
{
*pLen = index;
}
return TRUE;
}
BOOL BuildUsbKeyboardPacket(UINT8 *out, UINT8 maxLen, UINT8 *pLen, const UINT8 keyboard[KEYBOARD_LEN])
{
return BuildPacket(out, maxLen, pLen, ID_USB_KEYBOARD, keyboard, KEYBOARD_LEN);
}
BOOL BuildUsbMousePacket(UINT8 *out, UINT8 maxLen, UINT8 *pLen, const UINT8 mouse[MOUSE_LEN])
{
return BuildPacket(out, maxLen, pLen, ID_USB_MOUSE, mouse, MOUSE_LEN);
}
BOOL BuildPs2KeyboardPacket(UINT8 *out, UINT8 maxLen, UINT8 *pLen, const UINT8 keyboard[KEYBOARD_LEN])
{
return BuildPacket(out, maxLen, pLen, ID_PS2_KEYBOARD, keyboard, KEYBOARD_LEN);
}
BOOL BuildPs2MousePacket(UINT8 *out, UINT8 maxLen, UINT8 *pLen, const UINT8 mouse[MOUSE_LEN])
{
return BuildPacket(out, maxLen, pLen, ID_PS2_MOUSE, mouse, MOUSE_LEN);
}