// Control a NEC e616v mobile phone from GNU / Linux using libusb // Own portions are by Michael John Wensley - http://www.wensley.org.uk/c/e616v.c // Info is from http://e606iokit.sf.net/ // To compile this: gcc -o e616v e616v.c -lusb // | add to /etc/fstab (where GID = group id of group plugdev) // | none /proc/bus/usb usbfs devmode=0664,devgid=GID 0 0 // then: mount -o remount /proc/bus/usb // then add yourself to plugdev group // http://www.usb.org/developers/devclass_docs/usbcdc11.pdf // file:///usr/share/doc/libusb-dev/html/index.html // http://www.3gpp.org/ftp/Specs/html-info/27-series.htm // also do "modprobe usbserial vendor=0x409 product=0x10c" // after you have init'ed the phone with this program. // *********************************************** // Now you can talk to the e616v over the usb port! // e.g. minicom /dev/ttyUSB0 for AT commands ( 115200 8N1 ) // /dev/ttyUSB1 is probably OBEX and needs further // vendor commands :-/ // *********************************************** #include #include #include #include #include #include #include #include #include #include #include #define SEND_ENCAPSULATED_COMMAND 0x00 #define GET_ENCAPSULATED_RESPONSE 0x01 #define RESPONSE_AVAILABLE 0x01 #define GET_LINE_CODING 0x21 #define GET_COMM_FEATURE 0x03 #define ABSTRACT_STATE 0x01 #define TIMEOUT 0 #define READ 161 #define WRITE 33 // PHONEHACK = 0x41 #define OVI USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE // more fun... #define OCI USB_ENDPOINT_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE #define ICI USB_ENDPOINT_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE #define OSE USB_ENDPOINT_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT #define SET_LINE_CODING 0x20 #define GET_LINE_CODING 0x21 #define GET_COMM_FEATURE 0x03 #define SET_CONTROL_LINE_STATE 0x22 int phone(struct usb_device*); char buf[1024]; char* attention = "AT\r\n\0"; char* atwrap = "\0\4\1\1AT\r\n\0"; /** taken from http://e606iokit.sf.net/ drivers */ unsigned char init1[3] = { 0x03, 0x01, 0xC0 }, init2[3] = { 0x03, 0x60, 0xC0 }, init3[2] = { 0x02, 0x02 }; int main(int argc, char* argv[], char* envp[]) { int f, c, i, a; struct usb_bus *busses, *bus; struct usb_device *dev; usb_init(); f = usb_find_busses(); c = usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if ((dev->descriptor.idVendor == 0x0409) && (dev->descriptor.idProduct == 0x010c)) { return phone(dev); } } } fprintf(stderr, "NEC e616V NOT found\r\n"); return EXIT_FAILURE; } void init(usb_dev_handle *udev) { // this is the important proprietary bit.... based on // snoopypro.exe and http://e606iokit.sf.net/ int i; i = usb_control_msg(udev, OVI, 0x62, 0x00, 0x00, init1, 3, TIMEOUT); i = usb_control_msg(udev, OVI, 0x62, 0x00, 0x03, init2, 3, TIMEOUT); i = usb_control_msg(udev, OVI, 0x62, 0x00, 0x05, init3, 2, TIMEOUT); i = usb_control_msg(udev, OVI, 0x62, 0x00, 0x03, NULL, 0, TIMEOUT); i = usb_control_msg(udev, OVI, 0x62, 0x00, 0x05, NULL, 0, TIMEOUT); } void obexStart(usb_dev_handle *udev) { int i; i = usb_control_msg(udev, OSE, USB_REQ_SET_FEATURE, 0x00, 0x87, NULL, 0, TIMEOUT); i = usb_control_msg(udev, OVI, 0x60, 0x00, 0x03, NULL, 0, TIMEOUT); i = usb_control_msg(udev, OVI, 0x60, 0x00, 0x05, NULL, 0, TIMEOUT); i = usb_control_msg(udev, OVI, 0x60, 0x60, 0x03, NULL, 0, TIMEOUT); } void obexStop(usb_dev_handle *udev) { int i; i = usb_control_msg(udev, OSE, USB_REQ_SET_FEATURE, 0x00, 0x87, NULL, 0, TIMEOUT); i = usb_control_msg(udev, OVI, 0x60, 0x00, 0x03, NULL, 0, TIMEOUT); } // device has 9 endpoints // 0 0x81 - communication - Interrupt // 1 0x82 - get AT command responses - Bulk // 1 0x03 - Write your AT commands here - Bulk // 2 0x84 - data - Isochr // 2 0x05 - data - Isochr // 3 0x86 - communication - Intr // 4 0x87 - data - Bulk // 4 0x08 - data - Bulk // 5 0x89 - communication int phone(struct usb_device *dev) { int c,i, j, pid, d; usb_dev_handle *udev; int interface; interface = 0; udev = usb_open(dev); // if (dev->descriptor.iManufacturer) { // i = usb_get_string_simple(udev, dev->descriptor.iManufacturer, buf, sizeof(buf)); // if (i > -1) { // buf[i] = 0; // printf("Manufacturer %s", buf); // } // } i = usb_claim_interface(udev, 1); if (i < 0) { fprintf(stderr, "Cannot Claim phone\n\ Maybe you have usbserial modprobed? If modprobe -r'd, I can talk to the phone...\n\ You can load it again after."); return EXIT_FAILURE; } init(udev); // proprietary command i = usb_control_msg(udev, OVI, 0x60, 0x01, 0x00, NULL, 0, TIMEOUT); // obexStart(udev); usb_release_interface(udev, 1); usb_close(udev); return EXIT_SUCCESS; }