January 11, 2010
/* dnw2 linux main file. This depends on libusb.
* Author: Fox <firstname.lastname@example.org>
* License: GPL
#define QQ2440_SECBULK_IDVENDOR 0x5345
#define QQ2440_SECBULK_IDPRODUCT 0x1234
struct usb_dev_handle * open_port()
struct usb_bus *busses, *bus;
busses = usb_get_busses();
struct usb_device *dev;
printf("Target usb device found!n");
struct usb_dev_handle *hdev = usb_open(dev);
perror("Cannot open device");
perror("Cannot claim interface");
hdev = NULL;
printf("Target usb device not found!n");
printf("Usage: dnw2 <file>nn");
unsigned char* prepare_write_buf(char *filename, unsigned int *len)
unsigned char *write_buf = NULL;
struct stat fs;
int fd = open(filename, O_RDONLY);
perror("Cannot open file");
perror("Cannot get file size");
write_buf = (unsigned char*)malloc(fs.st_size+10);
if(fs.st_size != read(fd, write_buf+8, fs.st_size))
perror("Reading file failed");
printf("Filename : %sn", filename);
printf("Filesize : %d bytesn", fs.st_size);
*((u_int32_t*)write_buf) = 0x30000000; //download address
*((u_int32_t*)write_buf+1) = fs.st_size + 10; //download size;
*len = fs.st_size + 10;
fs.st_size = 0;
int main(int argc, char *argv)
struct usb_dev_handle *hdev = open_port();
unsigned int len = 0;
unsigned char* write_buf = prepare_write_buf(argv, &len);
if(NULL==write_buf) return 1;
unsigned int remain = len;
unsigned int towrite;
printf("Writing data ...n");
towrite = remain>512 ? 512 : remain;
if(towrite != usb_bulk_write(hdev, 0x03, write_buf+(len-remain), towrite, 3000))
printf("r%d%t %d bytes ", (len-remain)*100/len, len-remain);
To compile: gcc dnw2.c -o dnw2 -lusb
January 8, 2010
If you remote connect to UNIX from Windows, then it's likely you will bump into this error message at least once in your lifetime:
X connection to localhost:10.0 broken (explicit kill or server shutdown).
This error messages occurs when you try to execute an X Window graphics user interface software, but you haven't started the X Windows display software on your Windows machine.
The X Window display server that I prefer to use on Windows is Xming 22.214.171.124. It's available on SourceForge and it's low-maintenance. If you haven't gotten a X Window display server software, you might give it a try. After starting Xming, you should not have this problem again.
However, if this problem does occur when you have Xming running, it's probably because you did not enable X11 forwarding in PuTTY, or your ssh software.
Sun, 07 Jun 2009 18:35:41 +0000
Checklist for using Xming through a tunneled Putty session.
* In the Connection->SSH->X11 panel, set the Enable X11 forwarding checkbox.
* (optional) In the same panel, enter "localhost:0" as the X display location. This redirects forwarded X traffic to display number 0. Match the Xming Display number, set below.
* Generally, MIT-Magic-Cookie-1 (set by default) is the most common authentication protocol. This will be added/updated in your .Xauthority file after a successful login for each display (one per Putty session).
* In the Select display settings panel, set the Display number to 0. The IP port number used is 6000 + this number, so anything other than 0 will affect the display number used by X clients.
* In the same panel, if you want to connect directly from the remote client to the Xming server (not through Putty's X Forwarding), you should probably check the No Access Control box or your connection will be refused.
* Verify your SSH configuration allows X11 forwarding. In OpenSSH, the .ssh/config file should contain the entry "ForwardX11 yes".
* Your DISPLAY environment variable will be set automatically by Putty upon successful login. This will be "localhost:10.0" for the first session when the remote system's SSH daemon X11DisplayOffset is set to 10 (default). This display number will correspond to a TCP port that is listening on 6000 + display number, e.g. 6010. Use the command "netstat -an | grep -i listen" to see the ports on a Unix/Linux/Solaris box.
* If you "su" or "sudo" to a different user after login, you must merge the .Xauthority entry for the display associated with your session into the .Xauthority file of the new user. The DISPLAY environment variable should be set and exported the same as for the login user, for convenience. Otherwise, the X applications you lanuch with the new user will not have the authority to connect to your X server.
* For the "localhost" part of the X display location to be converted to the correct IP address, your hosts file (%SYSTEMROOT%\System32\drivers\etc\hosts) must contain the entry "127.0.0.1 localhost".
* IMPORTANT: If you are using Windows Vista, the hosts file does not contain this entry by default. Instead, there is a "::1 localhost", which is for IPv6 instead of IPv4. Comment out/delete that entry and add the entry " 127.0.0.1 localhost". This causes the "X connection to localhost:10.0 broken (explicit kill or server shutdown)" error to appear when you try to launch an X client application.
* If you use a firewall, make sure that Putty SSH is allowed through it. If you can't establish a login session with Putty, X applications aren't going to work, either.