UDE Invalid Device Descriptor - kmdf

I have been working through Microsoft's guide on USB Device Emulation and have reached the point that a virtual device shows up in my device manager, but reports an Invalid Device Descriptor.
Can you see any reason why the guide's example descriptor might be invalid?
//In this example, the descriptor declarations are assumed to be global variables,
//declared as shown here for a HID device just as an example:
const UCHAR g_UsbDeviceDescriptor[] = {
// Device Descriptor
0x12, // Descriptor Size
0x01, // Device Descriptor Type
0x00, 0x03, // USB 3.0
0x00, // Device class
0x00, // Device sub-class
0x00, // Device protocol
0x09, // Maxpacket size for EP0 : 2^9
0x5E, 0x04, // Vendor ID
0x39, 0x00, // Product ID
0x00, // LSB of firmware version
0x03, // MSB of firmware version
0x01, // Manufacture string index
0x03, // Product string index
0x00, // Serial number string index
0x01 // Number of configurations
};

Related

PN532 emulated card not read by an iphone but can with Android

I am using the PN532 as an emulator using the emulate_tag_ndef.ino example from arduino. I updated the emulate library according to another post (PN532 emulated card not read by an Android phone) to make it work, but it only works with Android. With iPhones I can only send up to 47 bytes, if succeeded.
Here's how I set the PN532_COMMAND_TGINITASTARGET command:
uint8_t command[] = {
PN532_COMMAND_TGINITASTARGET,
0x05, // MODE: 0x04 = PICC only, 0x01 = Passive only (0x02 = DEP only)
// MIFARE PARAMS
0x04, 0x00, // SENS_RES (seeeds studio set it to 0x04, nxp to 0x08)
0x00, 0x00, 0x00, // NFCID1t (is set over sketch with setUID())
0x20, // SEL_RES (0x20=Mifare DelFire, 0x60=custom)
// FELICA PARAMS
0x01, 0xFE, // NFCID2t (8 bytes) https://github.com/adafruit/Adafruit-PN532/blob/master/Adafruit_PN532.cpp FeliCa NEEDS TO BEGIN WITH 0x01 0xFE!
0x05, 0x01, 0x86,
0x04, 0x02, 0x02,
0x03, 0x00, // PAD (8 bytes)
0x4B, 0x02, 0x4F,
0x49, 0x8A, 0x00,
0xFF, 0xFF, // System code (2 bytes)
0x01, 0x01, 0x66, // NFCID3t (10 bytes)
0x6D, 0x01, 0x01, 0x10,
0x02, 0x00, 0x00,
0x00, // length of general bytes
0x00 // length of historical bytes
}
Does anyone know how I can make the iPhone write to the PN532? I am using the NFC Tools app to write to it. I have tried other apps but without any luck

Raw tcp send and recv

I'm making an application, using raw sockets and need your advice:
The application is a tester of some kind of tcp/ip stack.
What I need I have an application that connects with a remote server and transmits some data to id.
lets say - I cannot open sockets from my application - all I have is tcp/Ip buffer with all headers and so on.
For testing I wanna make 2 raw sockets - 1 for sending and 1 for receiving ip buffers.
for receiving i have this code:
int saddr_size , data_size;
struct sockaddr saddr;
unsigned char *buffer = (unsigned char *)malloc(65536); //Its Big!
printf("Starting...\n");
//Create a raw socket that shall sniff
sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_TCP);
if(sock_raw < 0)
{
printf("Socket Error\n");
return 1;
}
while(1)
{
saddr_size = sizeof saddr;
//Receive a packet
data_size = recvfrom(sock_raw , buffer , 65536 , 0 , &saddr , &saddr_size);
if(data_size <0 )
{
printf("Recvfrom error , failed to get packets\n");
return 1;
}
printf("Data size = %d", data_size);
}
close(sock_raw);
printf("Finished");
return 0;
And as I can see it works - it gets all TCP/IP packets.
For sender I tryed this
static const unsigned char pkt6[60] = {
0x32, 0x04, 0x34, 0xed, 0xf3, 0xab, 0x01, 0x02, /* 2.4..... */
0x03, 0x04, 0x05, 0x06, 0x08, 0x00, 0x45, 0x00, /* ......E. */
0x00, 0x2e, 0x00, 0x02, 0x00, 0x00, 0xff, 0x06, /* ........ */
0x44, 0xc5, 0xc0, 0xa8, 0x01, 0x02, 0xac, 0x11, /* D....... */
0x09, 0x47, 0x00, 0x08, 0x1a, 0x0b, 0x00, 0x00, /* .G...... */
0x19, 0x6e, 0x23, 0x17, 0xc8, 0x36, 0x50, 0x18, /* .n#..6P. */
0x08, 0x60, 0x2b, 0xb9, 0x00, 0x00, 0x6c, 0x6f, /* .`+...lo */
0x6f, 0x6c, 0x0a, 0x00 /* ol.. */
};
if((s = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) < 0) {
perror("error:");
exit(EXIT_FAILURE);
}
while(1) {
if(send(s, pkt6, sizeof(pkt6), 0)< 0)
perror("error::");
}
}
And it always says
error:: Destination address required
So what do I need to change if i want to send READy IP packets and get raw ip packets?
I've not use raw sockets this way myself, but AIUI you'll probably need to use sendto() instead of send(), and pass the saddr structure that you obtained in the recvfrom() call.

Display images from database, but only if request comes through a secured page

I have inherited a web application that displays a "photo roster" of students enrolled in a class. These images are protected by various regulations, so the rosters are only available to the instructor of the class. The images are stored as binary data in a SQL Server database,
In the original design, the images were served through a web handler file (.ashx) that returned an image based on a student ID value. The roster page limited users to selecting courses that were appropriate for them, thus protecting the images.
Now some administrators have learned to call the web handler file directly by modifying the URL. I would like to prevent this, and instead send the administrators through another protected page that limits their access based on business rules.
What options do I have for locking down the web handler/web service to only respond to requests that are embedded in a managed page? How can I prevent users from calling the handler directly?
You can perform the Authentication/Authorization logic inside the handler like this.
For example, the following code will display 404 error, if user is not login.
public class ImageHandler : IHttpHandler, IRequiresSessionState
{
// 1x1 transparent GIF
private readonly byte[] GifData =
{
0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
0x01, 0x00, 0x01, 0x00, 0x80, 0xff,
0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
0x02, 0x44, 0x01, 0x00, 0x3b
};
public void ProcessRequest(HttpContext context)
{
//if (context.User.IsInRole("Administrators"))
if (context.User.Identity.IsAuthenticated)
{
context.Response.ContentType = "image/gif";
context.Response.Buffer = false;
context.Response.OutputStream.Write(GifData, 0, GifData.Length);
}
else
{
context.Response.Write("File not found.");
context.Response.StatusCode = 404;
}
}
public bool IsReusable
{
get { return false; }
}
}

Send Arduino data via a Wi-Fi shield to a specific IP address on the LAN

I'm attempting to send sensor data from an Arduino Uno via a Copperhead Wi-Fi shield to a specific IP address and port on a LAN.
I can get the Copperhead Wi-Fi Server example sketch to work (pasted below). However, I'm not interested in responding to server requests via HTML. All I'm interested in is setting up a socket-like connection and sending data via TCP or UDP to IP address 192.168.0.3, port 1234.
I'm sure there is an easy solution to this, but as I am new to Arduino and my attempts to find a solution have been unsuccessful.
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,0,2}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"WiFi_AP"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
// Setup the wireless mode
// Infrastructure - connect to AP
// Adhoc - connect to another Wi-Fi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
// Check if the requested URL matches "/"
if (strcmp(URL, "/") == 0) {
// Use WiServer's print and println functions to write out the page content
WiServer.print("<html>");
WiServer.print("Hello World");
WiServer.print("</html>");
// URL was recognized
return true;
}
// URL not found
return false;
}
void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
WiServer.init(sendMyPage);
// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(57600);
WiServer.enableVerboseMode(true);
}
void loop(){
// Run WiServer
WiServer.server_task();
delay(10);
}
Looks like you are using the WiShield library. There should be an examples folder in the WiShield download with a SocketApp and UDPApp example. This is a good place to start.
A few things I learned while making a UDP app.
You may have to edit some #defines (e.g. APP_UDPAPP in apps-conf.h, UIP_CONF_UDP in uip-conf.h) before recompiling your app.
If you are doing a UDP app, keep in mind that you have a limited receive buffer (UIP_CONF_BUFFER_SIZE in uip-conf.h sets it to 400). My router was sending out a UDP broadcast XML message that was ~700 bytes which caused this buffer to overflow and over write other data. I don't think TCP will have this problem because it will negotiate a MSS that won't overrun the buffer.
In the end I made changes to the handle_connection() function in the UDPapp example. Below is a snippet (with uip_ipaddr set to 255.255.255.255).
void send_state(void) {
sprintf((char*)uip_appdata, "state %ld %ld %ld %c %d",
clock_time(),
state.sensors.ping[0].cm,
state.sensors.ping[1].cm,
state.actuators.chassis.direction,
state.actuators.chassis.speed);
uip_send(uip_appdata, strlen((char*)uip_appdata));
}
void send_beacon(void) {
if(timer_expired(&beacon_timer)) {
timer_reset(&beacon_timer);
sprintf((char*)uip_appdata, "beacon %ld", clock_time());
uip_send(uip_appdata, strlen((char*)uip_appdata));
uip_log("beacon sent");
}
}
boolean data_or_poll(void) {
return (uip_newdata() || uip_poll());
}
static PT_THREAD(handle_connection(void)) {
PT_BEGIN(&s.pt);
PT_WAIT_UNTIL(&s.pt, data_or_poll());
if(uip_newdata()) {
uip_flags &= (~UIP_NEWDATA);
send_state();
} else if (uip_poll()) {
uip_flags &= (~UIP_POLL);
send_beacon();
}
PT_END(&s.pt);
}
Did you get a chance to look at the Arduino WiFiWebClient tutorial? This example shows how to connect to a webserver and send an HTTP GET request.
You could create a simple server on any machine on the LAN and use the client library to connect to the server and send data using the write/print/println set of functions. I know its easier said than done, but thats the fun of programming isnt it?

Resolving errors in Arduino

I am working on a project, and I am trying to get a grasp of it. Using the WiShield. I have been trying to complete the example program for a simple tweeter. However, I have had no luck yet. I have been trying to find the solutions, and everything I find never seems to work. How do I fix this problem?
My code is below as well as the errors I receive.
Code
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char local_ip[] = {192,168,2,2};
unsigned char gateway_ip[] = {192,168,2,1};
unsigned char subnet_mask[] = {255,255,255,0};
const prog_char ssid[] PROGMEM = {"myssid"};
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
const prog_char security_passphrase[] PROGMEM = {"mywifipassword"};
prog_uchar wep_keys[] PROGMEM = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// Authentication string for the Twitter account.
char* auth = "[user:pass]"; // Base64 encoded USERNAME:PASSWORD
// This function generates a message with the current system time.
void currentTime() {
WiServer.print("Arduino has been running for ");
WiServer.printTime(millis());
}
// A request that sends a tweet using the currentTime function.
TWEETrequest sentMyTweet(auth, currentTime);
void setup() {
// Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages).
WiServer.init(NULL);
// Enable Serial output and ask WiServer to generate log messages (optional).
Serial.begin(57600);
WiServer.enableVerboseMode(true);
}
// Time (in milliseconds) when the next tweet should be sent.
long tweetTime = 0;
void loop(){
// Check if it's time to sent a tweet
if (millis() >= tweetTime) {
sentMyTweet.submit();
// Send next tweet 5 minutes from now
tweetTime += 1000 * 60 * 5;
}
// Run WiServer
WiServer.server_task();
delay(10);
}
Errors
In file included from SimpleTweeter.cpp:5:
C:\Program Files (x86)\arduino-1.0\libraries\WiShield/WiServer.h:198: error: conflicting return type specified for 'virtual void Server::write(uint8_t)'
C:\Program Files (x86)\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
SimpleTweeter.pde:-1: error: 'TWEETrequest' does not name a type
SimpleTweeter.cpp: In function 'void loop()':
SimpleTweeter.pde:-1: error: 'sentMyTweet' was not declared in this scope
(I am new to Arduino.)
It looks like the WiServer library hasn't been upgraded to work with Arduino 1.0. In this version of the Arduino software, the return type of the write method in the Print class was changed from void to size_t.
There is a fork of WiShield on GitHub by Juan C. Muller which makes it compatible with Arduino 1.0.
The subsequent error about the type TWEETrequest is a knock-on effect of this previous error.

Resources