1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
5 #define CMD_XFER 0x1E /* vmware backdoor transfer command */
8 XFER_OPEN
, /* open transfer channel */
9 XFER_SENDLEN
, /* specify length of data to send */
10 XFER_SEND
, /* send data */
11 XFER_RECVLEN
, /* get length of data to receive */
12 XFER_RECV
, /* receive data */
13 XFER_RECVACK
, /* acknowledge receipt of data */
14 XFER_CLOSE
/* close transfer channel */
17 #define STATUS(p) (HIWORD((p)[2]) & 0xff)
19 /*===========================================================================*
21 *===========================================================================*/
22 int channel_open(ch
, type
)
23 struct channel
*ch
; /* struct describing the new channel */
24 u32_t type
; /* channel type: CH_IN or CH_OUT */
26 /* Open a new backdoor channel. Upon success, the given channel structure will
27 * be filled with information and can be used in subsequent channel calls.
28 * Return OK on success, or a negative error code on error.
32 ptr
[1] = type
| 0x80000000;
33 ptr
[2] = MAKELONG(CMD_XFER
, XFER_OPEN
);
37 if ((STATUS(ptr
) & 1) == 0) return EIO
;
39 ch
->id
= HIWORD(ptr
[3]);
46 /*===========================================================================*
48 *===========================================================================*/
49 void channel_close(ch
)
50 struct channel
*ch
; /* backdoor channel to close */
52 /* Close a previously opened backdoor channel.
56 ptr
[2] = MAKELONG(CMD_XFER
, XFER_CLOSE
);
57 ptr
[3] = MAKELONG(0, ch
->id
);
64 /*===========================================================================*
66 *===========================================================================*/
67 int channel_send(ch
, buf
, len
)
68 struct channel
*ch
; /* backdoor channel to send to */
69 char *buf
; /* buffer to send data from */
70 int len
; /* size of the data to send */
72 /* Receive data over a backdoor channel. Return OK on success, or a negative
73 * error code on error.
78 ptr
[2] = MAKELONG(CMD_XFER
, XFER_SENDLEN
);
79 ptr
[3] = MAKELONG(0, ch
->id
);
85 if ((STATUS(ptr
) & 1) == 0) return EIO
;
87 if (len
== 0) return OK
;
89 ptr
[1] = MAKELONG(0, 1);
91 ptr
[3] = MAKELONG(0, ch
->id
);
101 /*===========================================================================*
103 *===========================================================================*/
104 int channel_recv(ch
, buf
, max
)
105 struct channel
*ch
; /* backdoor channel to receive from */
106 char *buf
; /* buffer to receive data into */
107 int max
; /* size of the buffer */
109 /* Receive data on a backdoor channel. Return the number of bytes received, or
110 * a negative error code on error.
115 ptr
[2] = MAKELONG(CMD_XFER
, XFER_RECVLEN
);
116 ptr
[3] = MAKELONG(0, ch
->id
);
117 ptr
[4] = ch
->cookie1
;
118 ptr
[5] = ch
->cookie2
;
122 if ((STATUS(ptr
) & 0x81) == 0) return EIO
;
124 if ((len
= ptr
[1]) == 0 || (STATUS(ptr
) & 3) == 1) return 0;
126 if (len
> max
) return E2BIG
;
128 ptr
[1] = MAKELONG(0, 1);
130 ptr
[3] = MAKELONG(0, ch
->id
);
131 ptr
[4] = ch
->cookie1
;
133 ptr
[6] = ch
->cookie2
;
138 ptr
[2] = MAKELONG(CMD_XFER
, XFER_RECVACK
);
139 ptr
[3] = MAKELONG(0, ch
->id
);
140 ptr
[4] = ch
->cookie1
;
141 ptr
[5] = ch
->cookie2
;