{"id":661,"date":"2011-01-23T08:21:46","date_gmt":"2011-01-23T00:21:46","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=661"},"modified":"2013-01-04T22:52:58","modified_gmt":"2013-01-04T14:52:58","slug":"ipcam-hacking-part-7","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2011\/01\/ipcam-hacking-part-7\/","title":{"rendered":"IPCam Hacking Part #7"},"content":{"rendered":"<p>Its been a while since I did any IPCam stuff, but I&#8217;ve now got most of the bits I needed together again, as well as a new laptop for dev work (curse the thieves that stole my last one!)<\/p>\n<p>As we recall from previous work, the main binary for the IPCam runs off a file called &#8220;camera&#8221;.<\/p>\n<p>As some people have discovered, it likes to reboot the equipment when its not happy (eg when the camera is unplugged, it has issues talking to hardware, or when someone has flashed the wrong firmware).<\/p>\n<p>So, lets take a look at the executable to see what interesting bits we can find out from it.<\/p>\n<p>#file camera tells us  &#8211; BINFLT file format. Fileflags: RAM GZIP.<br \/>\nSo we know its a compressed bflt elf &#8211; bflt stands for binary flat file, and it uses gzip compression. It also sits in ram.<\/p>\n<p>A hex dump of camera shows this for the first few bytes:<\/p>\n<p><code>62 46 4C 54 00 00 00 04  |   bFLT . . . . <\/code><\/p>\n<p>[<span style=\"color: red;\">Note &#8211; I had about 4 pages of #$%# work done on this, and WordPress decided to flake once finished due to an errant pasted 0x0 null byte above, cutting off the rest of my post, so this is going to be shorter and angrier than it was originally written. <br \/>Lesson learned, always save stuff elsewhere before posting.<\/span>]<\/p>\n<p>bFLT headers consist of 4 bytes identifier, then 4 bytes for the version number.<br \/>\nIn this case, its a version 4  bFLT file.<\/p>\n<p>If we take a look at the header file source for bflt at the uclinux site we see the below layout.<\/p>\n<p><code><br \/>\n      struct flat_hdr {<br \/>\n      \tchar magic[4];<br \/>\n      \tunsigned long rev;          \/* version *\/<br \/>\n      \tunsigned long entry;        \/* Offset of first executable instruction with text segment from beginning of file *\/<br \/>\n      \tunsigned long data_start;   \/* Offset of data segment from beginning of file *\/<br \/>\n      \tunsigned long data_end;     \/* Offset of end of data segment from beginning of file *\/<br \/>\n      \tunsigned long bss_end;      \/* Offset of end of bss segment from beginning of file *\/<br \/>\n      \t\/* (It is assumed that data_end through bss_end forms the bss segment.) *\/<br \/>\n      \tunsigned long stack_size;   \/* Size of stack, in bytes *\/<br \/>\n      \tunsigned long reloc_start;  \/* Offset of relocation records from beginning of file *\/<br \/>\n      \tunsigned long reloc_count;  \/* Number of relocation records *\/<br \/>\n      \tunsigned long flags;<br \/>\n      \tunsigned long filler[6];    \/* Reserved, set to zero *\/<br \/>\n      };<br \/>\n<\/code><\/p>\n<p>It doesn&#8217;t match up properly, as the sizes or code don&#8217;t make sense (yet).<\/p>\n<p>If we take a closer look, the header file has this to say:<\/p>\n<p><code><br \/>\n      #define FLAT_FLAG_RAM    0x0001 \/* load program entirely into RAM *\/<br \/>\n      #define FLAT_FLAG_GOTPIC 0x0002 \/* program is PIC with GOT *\/<br \/>\n      #define FLAT_FLAG_GZIP   0x0004 \/* all but the header is compressed *\/<br \/>\n<\/code><\/p>\n<p>Ahah!<\/p>\n<p>So, all but the header is compressed for a version 4 file.<\/p>\n<p>Lets check this out, and see if its correct.<br \/>\nExcluding the initial file identifier (bFLT), our header consists of  10 longs.  Thats 40 bytes long.<br \/>\nLets jump to offset 40 in the file, and see what we have there.<\/p>\n<p>1F 8B 08<\/p>\n<p>Those of you familiar with gzipped files will recognize that  &#8211; its the gzip header identifier.  So, so far, so good.<br \/>\nCompressed files aren&#8217;t very useful to us, as they don&#8217;t show much text content.<br \/>\nSo, we could unzip the file to take a look at whats inside.<\/p>\n<p>There are a number of ways we can unzip this (zcat, gzip -d etc), but I&#8217;m going to be lazy, and use someone elses premade code.<\/p>\n<p>See below for some perl to safely uncompress our binary , taken from here &#8211; <a href=\"http:\/\/www.openwiz.org\/wiki\/BWFWTools_Release\">http:\/\/www.openwiz.org\/wiki\/BWFWTools_Release<\/a><\/p>\n<p><code><br \/>\n#!\/usr\/bin\/perl<\/p>\n<p>=pod<\/p>\n<p>=head1 NAME<\/p>\n<p>gunzip_bflt - convert gzip-compressed bFLT executable files into uncompressed bFLT<\/p>\n<p>=head1 SYNOPSIS<\/p>\n<p>    gunzip_bflt zipped_blflt_files...<\/p>\n<p>=head1 DESCRIPTION<\/p>\n<p>Convert gzipped bFLT files into an uncompressed bFLT files.<br \/>\nThe unzipped bFLT files have B<.unz> added to their file names.<br \/>\nIf the file is already ungzipped bFLT, it isn't converted,<br \/>\nbut a warning is printed.<\/p>\n<p>=head1 PREREQUSITES<\/p>\n<p>Uses packages C<IO::Uncompress::Gunzip> and C<POSIX>.<\/p>\n<p>=cut<\/p>\n<p>use strict;<br \/>\nuse warnings;<\/p>\n<p># gunzip_bflt zipped_blflt_files...<\/p>\n<p>use IO::Uncompress::Gunzip qw\/gunzip $GunzipError\/;<br \/>\nuse POSIX;<\/p>\n<p># Read and return the BFLT header<br \/>\n# prints a warning and returns undef on error.<br \/>\n# $bfltZfh is the BFLT file handle,<br \/>\n# $bfltZ is the BFLT file name (for error messages)<\/p>\n<p>sub get_bflt_hdr($$) {<br \/>\n    my ($bfltZfh, $bfltZ) = @_;<br \/>\n    my $buf;<br \/>\n    my $res = sysread $bfltZfh, $buf, 64;<br \/>\n    if(!defined($res)) {<br \/>\n\twarn \"$bfltZ: $!\\n\";<br \/>\n\treturn undef;<br \/>\n    }<br \/>\n    if($res < 64) {\n\twarn \"$bfltZ: Too short!\\n\";\n\treturn undef;\n    }\n    # Align the buffered file handle with the unbuffered\n    seek $bfltZfh, sysseek($bfltZfh, 0, SEEK_CUR), SEEK_SET;\n    return $buf;\n}\n\n# Expand a gzipped BFLT intoi an ungziped BFLT\n\nsub expand_blftZ($) {\n    my ($bfltZ) = @_;\n    my $bflt = $bfltZ . '.unz';\n    if(!open BFLTZ, '<' . $bfltZ) {\n\twarn \"$bfltZ: $!\\n\";\n\treturn;\n    }\n    my $hdr = get_bflt_hdr(\\*BFLTZ, $bfltZ);\n    if(!defined $hdr) {\n\treturn;\n    }\n    if(substr($hdr, 0, 4) eq 'bFLT') {\n\t# Pack\/unpack template for the BFLT header, 4 bytes ACSII,\n\t# 15 little-endian words\n\tmy $hdrFmt = 'a4 N15';\n\n\tmy @unpHdr = unpack $hdrFmt, $hdr;\n\n\t# Test the header flags 'gzipped' bit\n\tif($unpHdr[9] &#038; 4) {\n\n\t    # Unset the header flags 'gzipped' bit, and make a new header\n\t    $unpHdr[9] &#038;= ~4;\n\t    $hdr = pack $hdrFmt, @unpHdr;\n\n\t    if(open BFLT, '>' . $bflt) {<\/p>\n<p>\t\t# Write the header<br \/>\n\t\tsyswrite BFLT, $hdr;<\/p>\n<p>\t\t# Align the buffered file handle with the unbuffered<br \/>\n\t\tseek BFLT, sysseek(BFLT, 0, SEEK_CUR), SEEK_SET;<\/p>\n<p>\t\t# Ungzip from the compressed file into the uncompressed<br \/>\n\t\t# file<br \/>\n\t\tgunzip \\*BFLTZ => \\*BFLT<br \/>\n\t\t    or die \"gunzip failed: $GunzipError\\n\";<\/p>\n<p>\t\tclose BFLTZ;<br \/>\n\t    } else {<br \/>\n\t\twarn \"$bflt: $!\\n\";<br \/>\n\t\treturn;<br \/>\n\t    }<br \/>\n\t} else {<br \/>\n\t    warn \"$bfltZ: Not a compressed bFLT file, not gunzipped\\n\";<br \/>\n\t    return;<br \/>\n\t}<br \/>\n    } else {<br \/>\n\twarn \"$bfltZ: Not a bFLT file\\n\";<br \/>\n    }<br \/>\n    close BFLT;<br \/>\n}<\/p>\n<p># Expand the arguments...<\/p>\n<p>foreach my $bfltZ (@ARGV) {<br \/>\n    expand_blftZ($bfltZ)<br \/>\n}<br \/>\n<\/code><\/p>\n<p>If we run that on our &#8216;camera&#8217; executable, we should have an uncompressed bFLT file as output &#8216;camera.unz&#8217;.<br \/>\nLets run strings on &#8216;camera.unz&#8217;, to see what interesting text content is in there.<\/p>\n<p>Some interesting things of note:<\/p>\n<p>From the variables list below, looks like there is a way to turn off the LED&#8230;<\/p>\n<blockquote><p>\nled_mode<br \/>\nptz_center_onstart<br \/>\nptz_auto_patrol_interval<br \/>\nptz_auto_patrol_type<br \/>\nptz_patrol_h_rounds<br \/>\nptz_patrol_v_rounds<br \/>\nptz_patrol_rate<br \/>\nptz_patrol_up_rate<br \/>\nptz_patrol_down_rate<br \/>\nptz_patrol_left_rate<br \/>\nptz_patrol_right_rate\n<\/p><\/blockquote>\n<p>We also have a full list of the internal cgi functions now, which might prove useful&#8230;<\/p>\n<blockquote><p>\nsnapshot.cgi<br \/>\nget_status.cgi<br \/>\nget_camera_params.cgi<br \/>\ndecoder_control.cgi<br \/>\ncamera_control.cgi<br \/>\nreboot.cgi<br \/>\nrestore_factory.cgi<br \/>\nupgrade_firmware.cgi<br \/>\nupgrade_htmls.cgi<br \/>\nget_params.cgi<br \/>\nset_alias.cgi<br \/>\nset_datetime.cgi<br \/>\nset_users.cgi<br \/>\nset_devices.cgi<br \/>\nset_network.cgi<br \/>\nset_wifi.cgi<br \/>\nset_pppoe.cgi<br \/>\nset_upnp.cgi<br \/>\nset_ddns.cgi<br \/>\nset_ftp.cgi<br \/>\nset_mail.cgi<br \/>\nset_alarm.cgi<br \/>\nvideostream.cgi<br \/>\nvideo.cgi<br \/>\ntest_ftp.cgi<br \/>\ntest_mail.cgi<br \/>\nset_misc.cgi<br \/>\nget_misc.cgi<br \/>\nset_p2p.cgi<br \/>\nget_p2p.cgi<br \/>\nset_forbidden.cgi<br \/>\nget_forbidden.cgi<br \/>\nset_decoder.cgi<br \/>\ncomm_write.cgi<br \/>\nwifi_scan.cgi<br \/>\nget_wifi_scan_result.cgi<br \/>\nget_log.cgi<br \/>\ncheck_user.cgi<br \/>\ncheck_user2.cgi<br \/>\nbackup_params.cgi<br \/>\nrestore_params.cgi<br \/>\nerase_allparams.cgi<br \/>\nset_mac.cgi<br \/>\ndo_cgi: unknown cgi\n<\/p><\/blockquote>\n<p>You can see that Maverick decided to fake the X-Mailer smtp header (Foxmail is a commonly used Mail Program in China).<\/p>\n<blockquote><p>\nMIME-Version: 1.0<br \/>\nContent-Type: multipart\/mixed;<br \/>\nboundary=&#8221;smtp_msg_boundary&#8221;<br \/>\nX-Mailer: Foxmail<br \/>\n&#8211;smtp_msg_boundary<br \/>\nContent-Type: image\/jpeg;<br \/>\nname=&#8221;%s(%s)_%c%s.jpg&#8221;<br \/>\nContent-Transfer-Encoding: base64<br \/>\n&#8211;smtp_msg_boundary&#8211;\n<\/p><\/blockquote>\n<p>I&#8217;m interested in why the firmware reboots on some firmwares though, so lets take a deeper look at the code.<\/p>\n<p>To do so, we&#8217;ll need to decompile it.<br \/>\nThe better equipped than me will probably use something like the nice ARM decompiler plugin for IDA-Pro called <a href=\"http:\/\/www.hex-rays.com\">Hex-Ray<\/a>.  Unfortunately that costs $$$, and I&#8217;m just a hobbyist.<\/p>\n<p>Luckily there is a free windows decompiler called arm2html available <a href=\"http:\/\/www.sigmaplayer.com\/filebase.php?d=1&#038;id=13&#038;c_old=5&#038;what=c&#038;page=1\">here.<\/a><br \/>\narm2html doesn&#8217;t handle compressed bFLT files though, so you&#8217;ll need to point it at the freshly ungzipped code you got from the perl script above.<\/p>\n<p>As we know that the camera executable reboots after issuing i2c errors, the first piece of decompiled code I wanted to look at was the first piece of code related to i2c:<\/p>\n<p>(excerpted piece below)<br \/>\n<code>02588:  e1a0c00d\tmov\tip, sp<br \/>\n00258c:  e92dd810\tstmdb\tsp!, {r4, fp, ip, lr, pc}<br \/>\n002590:  e24cb004\tsub\tfp, ip, #4\t; 0x4<br \/>\n002594:  e24dd00c\tsub\tsp, sp, #12\t; 0xc<br \/>\n002598:  e59f023c\tldr\tr0, [pc, #572] ; [0027dc]\t\"\/dev\/i2c0\"<br \/>\n00259c:  e3a01002\tmov\tr1, #2\t; 0x2<br \/>\n0025a0:  eb00c9b8\tbl\t034c88(c9b8)<br \/>\n0025a4:  e1a04000\tmov\tr4, r0<br \/>\n0025a8:  e3540000\tcmp\tr4, #0\t; 0x0<br \/>\n0025ac:  aa000003\tbge\t0025c0(3) ; jump<br \/>\n0025b0:  e59f0228\tldr\tr0, [pc, #552] ; [0027e0]\t\"%s: can not open i2c device\"<br \/>\n0025b4:  e59f1228\tldr\tr1, [pc, #552] ; [0027e4]\t\"zoom_test\"<br \/>\n0025b8:  eb00bc86\tbl\t0317d8(bc86)<br \/>\n0025bc:  e91ba810\tldmdb\tfp, {r4, fp, sp, pc} ; return<\/code><\/p>\n<p>The full piece of code essentially loops 7 times trying to open the i2c sensor to call the zoom_test code.  If it fails, it calls for a reboot.<br \/>\nSuccess proceeds to setting up the camera. <\/p>\n<p>We know from our boot log that my camera in this model is a Sonix288.<\/p>\n<blockquote><p>dvm usb cam driver 0.0.0.0 by Maverick Gao in 2006-8-12<br \/>\nusb.c: registered new driver dvm<br \/>\ndvm usb cam driver 0.1 for sonix288 by Maverick Gao in 2009-4-20<br \/>\nusb.c: registered new driver dvm usb cam driver for sonix288<\/p><\/blockquote>\n<p>The Sonix288 is a chipset SoC that will talk to an attached image sensor via i2c.  I think that the Sonix288 is probably a standard USB 1.1\/2.0 compatible UVC  (USB Video Class) chipset from a bit of googling about it.<\/p>\n<p>We don&#8217;t have the source for our particular camera though (its secret, much like the data sheets, grrr&#8230;).<br \/>\nWhat to do?<br \/>\nLinux generally uses spcaxxx (and UVC) drivers for talking to camera&#8217;s, so lets start taking a look there.<\/p>\n<p><a href=\"http:\/\/read.pudn.com\/downloads127\/sourcecode\/unix_linux\/539050\/zc030x\/zc030x_cameras.c__.htm\">http:\/\/read.pudn.com\/downloads127\/sourcecode\/unix_linux\/539050\/zc030x\/zc030x_cameras.c__.htm<br \/>\n<\/a><br \/>\n<a href=\"http:\/\/www.hackchina.com\/r\/54654\/zc030x_i2c.c__html\">http:\/\/www.hackchina.com\/r\/54654\/zc030x_i2c.c__html<\/a><\/p>\n<p>Taking a look at some spcaxxx driver header files and code shows that i2c is setup by first getting the USB VID, USB PID of the hardware, then talking to the i2c device on that hardware.<\/p>\n<p>So, we need to know what our USB VID and PID&#8217;s are.<\/p>\n<p>Generally all devices from a given manufacturer will have a single VID as issued by the USB Forum.<\/p>\n<p>If we search through the code for Sonix, it appears that Sonix&#8217;s VID is 0x0c45<\/p>\n<p><code>{USB_DEVICE(0x0c45, 0x607c)}, \/* Sonix sn9c102p Hv7131R *\/ <\/code><br \/>\n(from http:\/\/linux.downloadatoz.com\/linux-kernel-webcams-driver-gspca-spca5xx\/ )<\/p>\n<p>The Linux UVC page confirms this <a href=\"http:\/\/www.ideasonboard.org\/uvc\/\">http:\/\/www.ideasonboard.org\/uvc\/<\/a>.<\/p>\n<p>(Listings of webcams excerpted &#8211; note the VID of 0c45)<\/p>\n<blockquote><p>0c45:6310 \tUSB 2.0 Camera (Trust Chat Webcam) \tSonix Technology<br \/>\n0c45:63e0 \tSonix Integrated Webcam (Dell notebooks) \tSonix Technology<br \/>\n0c45:63ea \tLaptop Integrated Webcam 2M (Dell Studio 1555 notebooks) \tSonix Technology<br \/>\n0c45:6409 \tUSB 2.0 Camera (Nokia Booklet 3G netbooks) \tSonix Technology<br \/>\n0c45:6415 \tLaptop Integrated Webcam 1.3M (Dell Inspiron 13z notebooks) \tSonix Technology<\/p><\/blockquote>\n<p>Ideally at this point, I&#8217;d have a data sheet for the Sonix288 chip, but the #$%#$ people at <a href=\"http:\/\/www.sonix.com.tw\/\">Sonix<\/a> don&#8217;t seem to publish one for us mere mortals.<\/p>\n<p>So, we&#8217;ll use the next best thing, and use one for their other chipsets.<\/p>\n<p>SN9C1xx PC Camera Controllers &#8211;<br \/>\n<a href=\"http:\/\/ww2.cs.fsu.edu\/~rosentha\/linux\/2.6.26.5\/docs\/video4linux\/sn9c102.txt\">http:\/\/ww2.cs.fsu.edu\/~rosentha\/linux\/2.6.26.5\/docs\/video4linux\/sn9c102.txt<\/a><\/p>\n<p>There is a lot of good useful info in that particular file.  We don&#8217;t know how much is useful yet, but generally chipsets are quite similar for a given range.<\/p>\n<blockquote><p>\nImage sensor \/ SN9C1xx bridge      | SN9C10[12]  SN9C103  SN9C105  SN9C120<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nHV7131D    Hynix Semiconductor     | Yes         No       No       No<br \/>\nHV7131R    Hynix Semiconductor     | No          Yes      Yes      Yes<br \/>\nMI-0343    Micron Technology       | Yes         No       No       No<br \/>\nMI-0360    Micron Technology       | No          Yes      Yes      Yes<br \/>\nOV7630     OmniVision Technologies | Yes         Yes      Yes      Yes<br \/>\nOV7660     OmniVision Technologies | No          No       Yes      Yes<br \/>\nPAS106B    PixArt Imaging          | Yes         No       No       No<br \/>\nPAS202B    PixArt Imaging          | Yes         Yes      No       No<br \/>\nTAS5110C1B Taiwan Advanced Sensor  | Yes         No       No       No<br \/>\nTAS5110D   Taiwan Advanced Sensor  | Yes         No       No       No<br \/>\nTAS5130D1B Taiwan Advanced Sensor  | Yes         No       No       No\n<\/p><\/blockquote>\n<p>Interesting&#8230; Hmm, so it seems that Sonix uses a SN9Cxxx for its product names.<br \/>\nLets google for SN9C288 instead, and see if we get any results.<\/p>\n<p>Bingo.<\/p>\n<p>From here &#8211; <a href=\"http:\/\/www.lh-invest.com\/en\/showpro.asp?id=308&#038;proid=3\">www.lh-invest.com\/en\/showpro.asp?id=308&#038;proid=3<\/a><\/p>\n<blockquote><p>\n* MCU: SONIX SN9C288<br \/>\n* Sensor: MICRON K14 1,300,000 pixels CMOS<br \/>\n* 5-glass lens,can reach 30 frames\/sec. under 640*480<br \/>\n  resolutions,software insertion value 1,300,000 pixels<br \/>\n* Focus range: 3CM to infinitude farness<br \/>\n* Dynamic video resolutions: 1280*960 pixels(max.)<br \/>\n* Support microsoft UVC driver-free function<br \/>\n* Support RGB24 and YUY2 two kinds of image formats<br \/>\n* USB 2.0 port,support plug and play<br \/>\n* Human face tracking function\n<\/p><\/blockquote>\n<p>Seems our chipset is finally getting some details.<br \/>\nMax resolution, video modes, face tracking capability, etc<br \/>\nWe also know that it can be paired with a Micron K14 image sensor.<\/p>\n<p>Further googling reveals it can also be paired with the MI-0360 (which is listed above).<\/p>\n<p>SN9C288+MI0360<\/p>\n<p> This page also gives us a possible pid:<\/p>\n<p> <a href=\"http:\/\/forums.lenovo.com\/t5\/SL-Series-ThinkPad-Laptops\/camera-problem-in-all-windows-Creation-of-the-Video-preview\/m-p\/163019\/highlight\/true\">http:\/\/forums.lenovo.com\/t5\/SL-Series-ThinkPad-Laptops\/camera-problem-in-all-windows-Creation-of-the-Video-preview\/m-p\/163019\/highlight\/true<\/a><\/p>\n<blockquote><p>\n&#8220;Device Name: ?USB Video Device<\/p>\n<p>PnP Device ID: VID = 0C45 PID = 62C0<br \/>\nSerial Number: 6&#038;&#038;2BCAFCF3&#038;&#038;0&#038;&#038;0000<br \/>\nRevision: (Information not returned)<\/p>\n<p>Device Type: Standard USB device &#8211; USB2.0 High-Speed<\/p>\n<p>Chip Vendor: SONiX<br \/>\nChip Part-Number: SN9C288PFG<\/p>\n<\/blockquote>\n<p>In Microsoft parlance, this looks like this USB\\VID_0C45&#038;PID_62C0<\/p>\n<p>Googling that gives us a product with windows drivers (HP) and more.<\/p>\n<p><a href=\"http:\/\/www.downloadwindowsdrivers.info\/usb\/vid_0c45\/pid_62c0\/mi_00\/\">http:\/\/www.downloadwindowsdrivers.info\/usb\/vid_0c45\/pid_62c0\/mi_00\/<\/a><\/p>\n<p>Also says that these product drivers also work.<br \/>\nUSB\\VID_0C45&#038;PID_62C0 ;SN9C211\/213\/230<\/p>\n<p>That means we can take a look at their inf file and see if anything useful in there.  Unfortunately I did, and there isn&#8217;t much \ud83d\ude41<\/p>\n<p>Sonix has datasheets for some of their other products available though (SN9C2028AF).<\/p>\n<p>First, a quick overview of UVC devices (snarfed from elsewhere).<\/p>\n<p>USB devices are required by the USB specification to respond to the Host device (the computer) with a stream of data describing the device and the interface to the device.  This \u201cDevice Descriptor\u201d includes vendor, product, and version IDs specific to the manufacturer, the product, and the version of the product.  In addition to the device information, the descriptor also includes information on how to talk to the device through a series of \u201cInterface Descriptors\u201d.  <\/p>\n<p>The device descriptor for Video is 13.<\/p>\n<p>#define USB_DEVICE_CLASS_VIDEO         0x0E<\/p>\n<p>In addition to the end points described in the interface descriptors, all USB devices support a control pipe to end point 0.  This is used to manipulate some of the low level functions of the device such as power, and error status queries.<\/p>\n<p>The USB Video specification describes two interfaces, a control interface to manage the camera, and a stream interface to send or receive video information from the camera.   <\/p>\n<p>The control interface is used to manipulate the camera parameters such as brightness and contrast as well as to negotiate a valid set of the video format, frame size, frame rate, and compression rates parameters that describe a video stream.  In addition, the control interface can ask the camera for still frame.<\/p>\n<p>In the datasheet for the 2028, it basically states that they use end point 0 for STD Commands, with a maximum packet size of 64 bytes.<\/p>\n<p>Further googling reveals that there is no special driver for it, its a plain UVC 1.0 device.<\/p>\n<blockquote><p>usb 1-2: New USB device strings: Mfr=2, Product=1, SerialNumber=0<br \/>\nusb 1-2: Product: USB 2.0 Camera<br \/>\nusb 1-2: Manufacturer: Sonix Technology Co., Ltd.<br \/>\nLinux video capture interface: v2.00<br \/>\nuvcvideo: Found UVC 1.00 device USB 2.0 Camera<\/p><\/blockquote>\n<p>Further heavy baidu&#8217;ing in Chinese sites finds that the SN9C213 and SN9C288 are the same pretty much.<\/p>\n<p>\u5176\u5185\u90e8\u7f16\u53f7\u662fSN9C213\uff0c\u529f\u80fd\u5b8c\u5168\u548cSN9C288\u4e00\u6837\u3002From  <a href=\"http:\/\/ep.cbifamily.com\/2007\/04\/44\/87819.html\">http:\/\/ep.cbifamily.com\/2007\/04\/44\/87819.html<\/a><\/p>\n<p>David McCullough very nicely also compiled in usb debug support on his kernel and ran some tests too:<\/p>\n<p>> > > T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0<br \/>\n> > > D: Ver= 2.00 Cls=ef(unk. ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1<br \/>\n> > > P: Vendor=0c45 ProdID=62f1 Rev= 1.00<br \/>\n> > > S: Manufacturer=Sonix Technology Co., Ltd.<br \/>\n> > > S: Product=USB 2.0 Camera<br \/>\n> > > C:* #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=500mA<br \/>\n> > > I: If#= 0 Alt= 0 #EPs= 1 Cls=0e(unk. ) Sub=01 Prot=00 Driver=(none)<br \/>\n> > > E: Ad=83(I) Atr=03(Int.) MxPS= 16 Ivl=6ms<br \/>\n> > > I: If#= 1 Alt= 0 #EPs= 0 Cls=0e(unk. ) Sub=02 Prot=00 Driver=(none)<br \/>\n> > > I: If#= 1 Alt= 1 #EPs= 1 Cls=0e(unk. ) Sub=02 Prot=00 Driver=(none)<br \/>\n> > > E: Ad=81(I) Atr=05(Isoc) MxPS= 128 Ivl=1ms<br \/>\n> > > I: If#= 1 Alt= 2 #EPs= 1 Cls=0e(unk. ) Sub=02 Prot=00 Driver=(none)<br \/>\n> > > E: Ad=81(I) Atr=05(Isoc) MxPS= 256 Ivl=1ms<br \/>\n> > > I: If#= 1 Alt= 3 #EPs= 1 Cls=0e(unk. ) Sub=02 Prot=00 Driver=(none)<br \/>\n> > > E: Ad=81(I) Atr=05(Isoc) MxPS= 512 Ivl=1ms<br \/>\n> > > I: If#= 1 Alt= 4 #EPs= 1 Cls=0e(unk. ) Sub=02 Prot=00 Driver=(none)<br \/>\n> > > E: Ad=81(I) Atr=05(Isoc) MxPS= 600 Ivl=1ms<br \/>\n> > > I: If#= 1 Alt= 5 #EPs= 1 Cls=0e(unk. ) Sub=02 Prot=00 Driver=(none)<br \/>\n> > > E: Ad=81(I) Atr=05(Isoc) MxPS= 800 Ivl=1ms<br \/>\n> > > I: If#= 1 Alt= 6 #EPs= 1 Cls=0e(unk. ) Sub=02 Prot=00 Driver=(none)<br \/>\n> > > E: Ad=81(I) Atr=05(Isoc) MxPS= 956 Ivl=1ms<\/p>\n<p>The uvc driver status is obviously an issue as we&#8217;re on a 2.4 Kernel.  No uvc support on 2.4.<br \/>\nSo&#8230;, we either compile 2.6 with UVC support, and reflash, or we continue to use Mavericks driver in lieu of any source.<\/p>\n<p>With that, you have some background on things..<br \/>\nNow, why does this cause a reboot on some machines?<\/p>\n<p>Well, the hardware is different, so the hardware isn&#8217;t seen by the driver.<br \/>\nFrom looking at a few different boards I have seen a few devices id&#8217;s used.<\/p>\n<p>So far I have seen these:<br \/>\n<strong>vid_0c45\/pid_62f1<\/strong> &#8211;   (The Sonix Chipset allows you to write pid&#8217;s into the device, so this can be changed, or alternately change the driver from 62c0 to 62f1 on these models)<\/p>\n<p><strong>vid_0c45\/pid_62c0<\/strong> &#8211;    (Our driver is compiled for this)<\/p>\n<p>For those of you with rebooting machines, remove &#8216;camera &#038;&#8217; from the boot sequence, recompile the kernel with USB verbose debug message logging, and start posting your vid\/pid&#8217;s here so we can compare, and add to the list.<\/p>\n<p>If someone twisted my arm I could probably oblige&#8230;<\/p>\n<p><strong>References:<\/strong><br \/>\n<a href=\"http:\/\/www.beyondlogic.org\/uClinux\/bflt.htm\">http:\/\/www.beyondlogic.org\/uClinux\/bflt.htm<\/a> &#8211; bFLT file format details.<br \/>\n<a href=\"http:\/\/www.garykessler.net\/library\/file_sigs.html\">http:\/\/www.garykessler.net\/library\/file_sigs.html<\/a> &#8211; Common file format headers<br \/>\n<a href=\"http:\/\/www.openwiz.org\/wiki\/BWFWTools_Release\">http:\/\/www.openwiz.org\/wiki\/BWFWTools_Release<\/a> &#8211; bFLT unzip and other tools<br \/>\n<a href=\"http:\/\/www.hex-rays.com\">http:\/\/www.hex-rays.com<\/a> &#8211; IDA Pro and Hex-Ray ARM Decompiler<br \/>\n<a href=\"http:\/\/www.sigmaplayer.com\/filebase.php?d=1&#038;id=13&#038;c_old=5&#038;what=c&#038;page=1\">http:\/\/www.sigmaplayer.com\/filebase.php?d=1&#038;id=13&#038;c_old=5&#038;what=c&#038;page=1<\/a> &#8211; Arm Decompiler<br \/>\n<a href=\"http:\/\/www.ideasonboard.org\/uvc\/\">http:\/\/www.ideasonboard.org\/uvc\/<\/a><br \/>\n<a href=\"http:\/\/read.pudn.com\/downloads127\/sourcecode\/unix_linux\/539050\/zc030x\/zc030x_cameras.c__.htm\">http:\/\/read.pudn.com\/downloads127\/sourcecode\/unix_linux\/539050\/zc030x\/zc030x_cameras.c__.htm<\/a><br \/>\n<a href=\"http:\/\/www.hackchina.com\/r\/54654\/zc030x_i2c.c__html\">http:\/\/www.hackchina.com\/r\/54654\/zc030x_i2c.c__html<\/a><br \/>\n<a href=\"http:\/\/linux.downloadatoz.com\/linux-kernel-webcams-driver-gspca-spca5xx\/\">http:\/\/linux.downloadatoz.com\/linux-kernel-webcams-driver-gspca-spca5xx\/<\/a><br \/>\n<a href=\"http:\/\/ww2.cs.fsu.edu\/~rosentha\/linux\/2.6.26.5\/docs\/video4linux\/sn9c102.txt\">http:\/\/ww2.cs.fsu.edu\/~rosentha\/linux\/2.6.26.5\/docs\/video4linux\/sn9c102.txt<\/a><\/p>\n<p><strong>Files from this post:<\/strong><br \/>\n(arm2html.exe, bFLT gunzip perl script, original camera bFLT, uncompressed camera bFLT, and camera asm source )<br \/>\n<a href='http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2011\/01\/Camera-Disassembly-unpacked-bFLT-and-Tools.zip'>Camera Disassembly, unpacked bFLT and Tools<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Its been a while since I did any IPCam stuff, but I&#8217;ve now got most of the bits I needed together again, as well as a new laptop for dev work (curse the thieves that stole my last one!) As we recall from previous work, the main binary for the IPCam runs off a file [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[282,252],"tags":[248,258,245,118,240,250,249,247],"class_list":["post-661","post","type-post","status-publish","format-standard","hentry","category-firmware-2","category-ip-cam","tag-arm7","tag-debian","tag-foscam","tag-howto","tag-ipcam","tag-nc745","tag-nuvoton","tag-uclinux"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/comments?post=661"}],"version-history":[{"count":8,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/661\/revisions"}],"predecessor-version":[{"id":922,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/661\/revisions\/922"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}