3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 * RNDOS Device commands, to issue RNDIS commands to the device for
34 * the control and data transfer between the host and RNDIS device.
37 #include "RNDISCommands.h"
39 uint32_t RequestID
= 0;
41 uint8_t RNDIS_SendEncapsulatedCommand(void* Buffer
, uint16_t Length
)
43 USB_ControlRequest
= (USB_Request_Header_t
)
45 .bmRequestType
= (REQDIR_HOSTTODEVICE
| REQTYPE_CLASS
| REQREC_INTERFACE
),
46 .bRequest
= REQ_SendEncapsulatedCommand
,
52 printf("==== RNDIS CONTROL REQUEST ====\r\n");
53 uint8_t* Data
= Buffer
;
54 for (uint16_t i
= 0; i
< Length
/ 8; i
++)
56 for (uint16_t j
= 0; (j
< 8) && i
*8+j
< Length
; j
++)
57 printf("%02X ", *(Data
++));
61 printf("==== ********************* ====\r\n");
63 /* Select the control pipe for the request transfer */
64 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
66 return USB_Host_SendControlRequest(Buffer
);
69 uint8_t RNDIS_GetEncapsulatedResponse(void* Buffer
, uint16_t Length
)
71 USB_ControlRequest
= (USB_Request_Header_t
)
73 .bmRequestType
= (REQDIR_DEVICETOHOST
| REQTYPE_CLASS
| REQREC_INTERFACE
),
74 .bRequest
= REQ_GetEncapsulatedResponse
,
80 /* Select the control pipe for the request transfer */
81 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
83 return USB_Host_SendControlRequest(Buffer
);
86 uint8_t RNDIS_InitializeDevice(uint16_t MaxPacketSize
, RNDIS_Initialize_Complete_t
* InitMessageResponse
)
90 RNDIS_Initialize_Message_t InitMessage
;
92 InitMessage
.MessageType
= REMOTE_NDIS_INITIALIZE_MSG
;
93 InitMessage
.MessageLength
= sizeof(RNDIS_Initialize_Message_t
);
94 InitMessage
.RequestId
= RequestID
++;
95 InitMessage
.MajorVersion
= REMOTE_NDIS_VERSION_MAJOR
;
96 InitMessage
.MinorVersion
= REMOTE_NDIS_VERSION_MINOR
;
97 InitMessage
.MaxTransferSize
= sizeof(RNDIS_Packet_Message_t
) + MaxPacketSize
;
99 if ((ErrorCode
= RNDIS_SendEncapsulatedCommand(&InitMessage
,
100 sizeof(RNDIS_Initialize_Message_t
))) != HOST_SENDCONTROL_Successful
)
105 if ((ErrorCode
= RNDIS_GetEncapsulatedResponse(InitMessageResponse
,
106 sizeof(RNDIS_Initialize_Complete_t
))) != HOST_SENDCONTROL_Successful
)
111 return HOST_SENDCONTROL_Successful
;
114 uint8_t RNDIS_SetRNDISProperty(uint32_t Oid
, void* Buffer
, uint16_t Length
)
120 RNDIS_Set_Message_t SetMessage
;
121 uint8_t ContigiousBuffer
[Length
];
124 RNDIS_Set_Complete_t SetMessageResponse
;
126 SetMessageData
.SetMessage
.MessageType
= REMOTE_NDIS_SET_MSG
;
127 SetMessageData
.SetMessage
.MessageLength
= sizeof(RNDIS_Set_Message_t
) + Length
;
128 SetMessageData
.SetMessage
.RequestId
= RequestID
++;
130 SetMessageData
.SetMessage
.Oid
= Oid
;
131 SetMessageData
.SetMessage
.InformationBufferLength
= Length
;
132 SetMessageData
.SetMessage
.InformationBufferOffset
= 0;
133 SetMessageData
.SetMessage
.DeviceVcHandle
= 0;
136 if ((ErrorCode
= RNDIS_SendEncapsulatedCommand(&SetMessageData
,
137 SetMessageData
.SetMessage
.MessageLength
)) != HOST_SENDCONTROL_Successful
)
142 if ((ErrorCode
= RNDIS_GetEncapsulatedResponse(&SetMessageResponse
,
143 sizeof(RNDIS_Set_Complete_t
))) != HOST_SENDCONTROL_Successful
)
148 return HOST_SENDCONTROL_Successful
;