һ. V4L2: video for linux version 2


Ƶvivi.c:
1video_device
2
3ע᣺video_register_device

vivi_init
    vivi_create_instance
        v4l2_device_register   // Ҫ, ֻڳʼһЩü
        video_device_alloc
        // 
          1. vfd:
            .fops           = &vivi_fops,
            .ioctl_ops 	= &vivi_ioctl_ops,
            .release	= video_device_release,
          2.
            vfd->v4l2_dev = &dev->v4l2_dev;
          3. "ctrl"(APPioctl)
            	v4l2_ctrl_handler_init(hdl, 11);
            	dev->volume = v4l2_ctrl_new_std(hdl, &vivi_ctrl_ops,
            			V4L2_CID_AUDIO_VOLUME, 0, 255, 1, 200);
            	dev->brightness = v4l2_ctrl_new_std(hdl, &vivi_ctrl_ops,
            			V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
            	dev->contrast = v4l2_ctrl_new_std(hdl, &vivi_ctrl_ops,
            			V4L2_CID_CONTRAST, 0, 255, 1, 16);                        
        video_register_device(video_device, type:VFL_TYPE_GRABBER, nr)
            __video_register_device
                vdev->cdev = cdev_alloc();
                vdev->cdev->ops = &v4l2_fops;
                cdev_add
                
                video_device[vdev->minor] = vdev;

        		if (vdev->ctrl_handler == NULL)
        			vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
                
                

vivi.copen,read,write,ioctl
1. open
app:     open("/dev/video0",....)
---------------------------------------------------
drv:     v4l2_fops.v4l2_open
            vdev = video_devdata(filp);  // ݴ豸Ŵеõvideo_device
            ret = vdev->fops->open(filp);
                        vivi_ioctl_ops.open
                            v4l2_fh_open

2. read
app:    read ....
---------------------------------------------------
drv:    v4l2_fops.v4l2_read
            struct video_device *vdev = video_devdata(filp);
            ret = vdev->fops->read(filp, buf, sz, off);

3. ioctl
app:   ioctl
----------------------------------------------------
drv:   v4l2_fops.unlocked_ioctl
            v4l2_ioctl
                struct video_device *vdev = video_devdata(filp);
                ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
                            video_ioctl2
                                video_usercopy(file, cmd, arg, __video_do_ioctl);
                                    __video_do_ioctl
                                        struct video_device *vfd = video_devdata(file);
                                        APPcmdá"ĳЩ"

v4l2_ctrl_handlerʹù:
    __video_do_ioctl
        struct video_device *vfd = video_devdata(file);

    	case VIDIOC_QUERYCTRL:
    	{
    		struct v4l2_queryctrl *p = arg;
    
    		if (vfh && vfh->ctrl_handler)
    			ret = v4l2_queryctrl(vfh->ctrl_handler, p);
    		else if (vfd->ctrl_handler)  // ãvideo_register_device
    			ret = v4l2_queryctrl(vfd->ctrl_handler, p);
    			            // IDctrl_handlerҵv4l2_ctrlֵ
                                                

vivi
׼װxawtv
sudo apt-get install xawtv

Դxawtv-3.95.tar.gz
http://www.kraxel.org/releases/xawtv/

վµsources.list
http://repogen.simplylinux.ch/
1. ѡ
2ѡڵubuntu汾
3. ѡ"Ubuntu Branches"
4. sources.list
5. ѵõ滻/etc/apt/sources.list
6. sudo apt-get update
   sudo apt-get install xawtv

USBͷ
1VMWAERǰ̨USBͷԿ/dev/video0
2ִ xawtv ɿͼ

ͷvivi
1. ȷʵubuntuں˰汾
uname -a
Linux book-desktop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 i686 GNU/Linux
2. ȥwww.kernel.orgͬ汾ں
   ѹdrivers/media/videoĿ¼ȡ
   ޸MakefileΪ

KERN_DIR = /usr/src/linux-headers-2.6.31-14-generic

all:
        make -C $(KERN_DIR) M=`pwd` modules 

clean:
        make -C $(KERN_DIR) M=`pwd` modules clean
        rm -rf modules.order

obj-m   += vivi.o
obj-m   += videobuf-core.o
obj-m   += videobuf-vmalloc.o
obj-m   += v4l2-common.o
   
3. make
4. sudo modprobe vivi  
   sudo rmmod vivi
   sudo insmod ./vivi.ko

5. ls /dev/video*
6. xawtv -c /dev/videoX


//
3. ioctl(4, VIDIOC_G_FMT
4. for()
        ioctl(4, VIDIOC_ENUM_FMT
5. ioctl(4, VIDIOC_QUERYCAP    // о
6. ioctl(4, VIDIOC_G_INPUT     // õǰʹԴ
7. ioctl(4, VIDIOC_ENUMINPUT   // оԴ
8. ioctl(4, VIDIOC_QUERYCTRL   // ѯ,ȡԱȶ
9. ioctl(4, VIDIOC_QUERYCAP
10. ioctl(4, VIDIOC_ENUMINPUT

viviʹù̳׷ͷ
// 1~7v4l2_open
1. open
2. ioctl(4, VIDIOC_QUERYCAP

// 3~7 get_device_capabilities
3. for()
        ioctl(4, VIDIOC_ENUMINPUT   // оԴ,VIDIOC_ENUMINPUT/VIDIOC_G_INPUT/VIDIOC_S_INPUTǱ
4. for()
        ioctl(4, VIDIOC_ENUMSTD  // оٱ׼(ʽ), Ǳ
5. for()        
        ioctl(4, VIDIOC_ENUM_FMT // оٸʽ

6. ioctl(4, VIDIOC_G_PARM
7. for()
        ioctl(4, VIDIOC_QUERYCTRL    // ѯ(˵ֵСֵֵĬֵ)

// 8~10ͨv4l2_read_attrõ        
8. ioctl(4, VIDIOC_G_STD            // õǰʹõı׼(ʽ), Ǳ
9. ioctl(4, VIDIOC_G_INPUT 
10. ioctl(4, VIDIOC_G_CTRL           // õǰ, Ƕ

11. ioctl(4, VIDIOC_TRY_FMT          // ܷ֧ĳָʽ
12. ioctl(4, VIDIOC_S_FMT            // ͷʹĳָʽ


// 13~16v4l2_start_streaming
13. ioctl(4, VIDIOC_REQBUFS          // ϵͳ仺
14. for()
        ioctl(4, VIDIOC_QUERYBUF         // ѯĻ
        mmap        
15. for ()
        ioctl(4, VIDIOC_QBUF             // ѻ        
16. ioctl(4, VIDIOC_STREAMON             // ͷ


// 17ﶼͨv4l2_write_attrõ
17. for ()
        ioctl(4, VIDIOC_S_CTRL           // 
    ioctl(4, VIDIOC_S_INPUT              // Դ
    ioctl(4, VIDIOC_S_STD                // ñ׼(ʽ), Ǳ

// v4l2_nextframe > v4l2_waiton    
18. v4l2_queue_all
    v4l2_waiton    
        for ()
        {
            select(5, [4], NULL, NULL, {5, 0})      = 1 (in [4], left {4, 985979})
            ioctl(4, VIDIOC_DQBUF                // de-queue, ѻӶȡ
            // , ֮Ѿͨmmap˻ĵַ, Ϳֱӷ        
            ioctl(4, VIDIOC_QBUF                 // ѻ
        }

xawtvļ
1. v4l2_open
2. v4l2_read_attr/v4l2_write_attr
3. v4l2_start_streaming
4. v4l2_nextframe/v4l2_waiton

ͷ11ioctl:
    // ʾһͷ豸
	.vidioc_querycap      = vidioc_querycap,

    /* о١áԡͷݵĸʽ */
	.vidioc_enum_fmt_vid_cap  = vidioc_enum_fmt_vid_cap,
	.vidioc_g_fmt_vid_cap     = vidioc_g_fmt_vid_cap,
	.vidioc_try_fmt_vid_cap   = vidioc_try_fmt_vid_cap,
	.vidioc_s_fmt_vid_cap     = vidioc_s_fmt_vid_cap,

    /* : /ѯ//ȡ */
	.vidioc_reqbufs       = vidioc_reqbufs,
	.vidioc_querybuf      = vidioc_querybuf,
	.vidioc_qbuf          = vidioc_qbuf,
	.vidioc_dqbuf         = vidioc_dqbuf,

	// /ֹͣ
	.vidioc_streamon      = vidioc_streamon,
	.vidioc_streamoff     = vidioc_streamoff,	
     
ݵĻȡ̣
1. 仺: ioctl(4, VIDIOC_REQBUFS          // ϵͳ仺
                        videobuf_reqbufs(, v4l2_requestbuffers) // openvideobuf_queue_vmalloc_initʼ
                        // ע⣺IOCTLֻǷ仺ͷϢĻ滹ûз

2. ѯӳ仺:
ioctl(4, VIDIOC_QUERYBUF         // ѯĻ
        videobuf_querybuf        // ûݸʽСÿһгȡ߶            
mmap("С")   // ŷ仺
        v4l2_mmap
            vivi_mmap
                videobuf_mmap_mapper
                    videobuf-vmalloc.c__videobuf_mmap_mapper
                            mem->vmalloc = vmalloc_user(pages);   // Ÿռ

3. ѻ:
ioctl(4, VIDIOC_QBUF             // ѻ        
    videobuf_qbuf
        q->ops->buf_prepare(q, buf, field);  // ṩĺЩԤ
        list_add_tail(&buf->stream, &q->stream);  // ѻеβ
        q->ops->buf_queue(q, buf);           // ṩ"к"
        

4. ͷ
ioctl(4, VIDIOC_STREAMON
    videobuf_streamon
        q->streaming = 1;
        

5. selectѯǷ
          // ض: ݡѽ
          v4l2_poll
                vdev->fops->poll
                    vivi_poll   
                        videobuf_poll_stream
                            // Ӷеͷû
                			buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
                            
                            // û                			
                			poll_wait(file, &buf->done, wait);

    ˭ݡ˭
    ں߳vivi_threadÿ30MSִһΣ
    vivi_thread_tick
        vivi_fillbuff(fh, buf);  //  
        wake_up(&buf->vb.done);  // ѽ
          
6. ݺӶȡ
// ô໺APP֪һݣVIDIOC_DQBUF
ioctl(4, VIDIOC_DQBUF 
    vidioc_dqbuf   
        // ڶݵĻ
        retval = stream_next_buffer(q, &buf, nonblocking);
        
        // Ӷɾ
        list_del(&buf->stream);
        
        // ״̬ظAPP
        videobuf_status(q, b, buf, q->type);
        
7. ӦóVIDIOC_DQBUFõ״̬֪һ
   ȥӦĵַ(õַǰmmap)

ôдͷ:
1. video_device:video_device_alloc
2. 
   .fops
   .ioctl_ops (Ҫ11)
   ҪںṩĻҪһvideobuf_queue_ops
3. ע: video_register_device

ġԼдһͷ

塢дһUSBͷ
1.һusb_driver
2.
   probe:
        2.1. video_device:video_device_alloc
        2.2. 
           .fops
           .ioctl_ops (Ҫ11)
           ҪںṩĻҪһvideobuf_queue_ops
        2.3. ע: video_register_device      
  id_table: ʾ֧ЩUSB豸      
3.ע᣺ usb_register
 
UVC: USB Video Class
UVCdrivers\media\video\uvc\

uvc_driver.c:
1. usb_register(&uvc_driver.driver);
2. uvc_probe
        uvc_register_video
            vdev = video_device_alloc();
            vdev->fops = &uvc_fops;
            video_register_device

www.usb.org uvc specification,
UVC 1.5 Class specification.pdf : ϸ
USB_Video_Example 1.5.pdf    : ʾ

ͨVideoControl Interfaceƣ
ͨVideoStreaming InterfaceƵݣ
VCﺬжUnit/Terminalȹģ飬ͨЩģпƣ
            
UVCụ̀
const struct v4l2_file_operations uvc_fops = {
	.owner		= THIS_MODULE,
	.open		= uvc_v4l2_open,
	.release	= uvc_v4l2_release,
	.ioctl		= uvc_v4l2_ioctl,
	.read		= uvc_v4l2_read,
	.mmap		= uvc_v4l2_mmap,
	.poll		= uvc_v4l2_poll,
};

1. open:
        uvc_v4l2_open
2. VIDIOC_QUERYCAP   // video->streaming->type Ӧ豸öʱʱõ
		if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
			cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
					  | V4L2_CAP_STREAMING;
		else
			cap->capabilities = V4L2_CAP_VIDEO_OUTPUT
					  | V4L2_CAP_STREAMING;
3. VIDIOC_ENUM_FMT // formatӦ豸öʱõ
        format = &video->streaming->format[fmt->index];
4. VIDIOC_G_FMT
        uvc_v4l2_get_format  // USBͷֶָ֧ʽfromat, ÿָʽжframe(ֱ)
            	struct uvc_format *format = video->streaming->cur_format;
            	struct uvc_frame *frame = video->streaming->cur_frame;
5. VIDIOC_TRY_FMT
        uvc_v4l2_try_format
            /* Check if the hardware supports the requested format. */

        	/* Find the closest image size. The distance between image sizes is
        	 * the size in pixels of the non-overlapping regions between the
        	 * requested size and the frame-specified size.
        	 */
6. VIDIOC_S_FMT  // ֻǰѲûзUSBͷ
        uvc_v4l2_set_format
            uvc_v4l2_try_format
        	video->streaming->cur_format = format;
        	video->streaming->cur_frame = frame;
7. VIDIOC_REQBUFS
        uvc_alloc_buffers
           	for (; nbuffers > 0; --nbuffers) {
        		mem = vmalloc_32(nbuffers * bufsize);
        		if (mem != NULL)
        			break;
        	}
8. VIDIOC_QUERYBUF
        uvc_query_buffer
            __uvc_query_buffer
                memcpy(v4l2_buf, &buf->buf, sizeof *v4l2_buf);  // Ʋ
9. mmap
        uvc_v4l2_mmap
            
10. VIDIOC_QBUF
        uvc_queue_buffer
        	list_add_tail(&buf->stream, &queue->mainqueue);
        	list_add_tail(&buf->queue, &queue->irqqueue);

11. VIDIOC_STREAMON
        uvc_video_enable(video, 1)  // õĲӲ,Ȼͷ
            /* Commit the streaming parameters. */
            uvc_commit_video
                uvc_set_video_ctrl  /* øʽfromat, frame */
                    	ret = __uvc_query_ctrl(video->dev /* һUSB豸 */, SET_CUR, 0,
                    		video->streaming->intfnum  /* һӿ: VS */,
                    		probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, data, size,
                    		uvc_timeout_param);
                    
            /* Initialize isochronous/bulk URBs and allocate transfer buffers. */
            uvc_init_video(video, GFP_KERNEL);
                    uvc_init_video_isoc / uvc_init_video_bulk
                        urb->complete = uvc_video_complete; (յݺ˺,ֵvideo->decode(urb, video, buf); ==> uvc_video_decode_isoc/uvc_video_encode_bulk => uvc_queue_next_buffer => wake_up(&buf->wait);)
                        
                    usb_submit_urb                    	
12. poll
        uvc_v4l2_poll            
            uvc_queue_poll
                poll_wait(file, &buf->wait, wait);  // ߵȴ

13. VIDIOC_DQBUF
        uvc_dequeue_buffer
        	list_del(&buf->stream);

14. VIDIOC_STREAMOFF            
        uvc_video_enable(video, 0);
    		usb_kill_urb(urb);
    		usb_free_urb(urb);
        
ȹ̣
ioctl: VIDIOC_S_CTRL
            uvc_ctrl_set
            uvc_ctrl_commit
                __uvc_ctrl_commit(video, 0);
                    uvc_ctrl_commit_entity(video->dev, entity, rollback);
                			ret = uvc_query_ctrl(dev  /* һUSB豸 */, SET_CUR, ctrl->entity->id  /* һunit/terminal */,
                				dev->intfnum /* һӿ: VC interface */, ctrl->info->selector,
                				uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
                				ctrl->info->size);
                        
     
ܽ᣺
1. UVC豸2interface: VideoControl Interface, VideoStreaming Interface
2. VideoControl InterfaceڿƣȡڲжUnit/Terminal(ڳUnit/TerminalΪentity)
   ͨƵĺʣ
                			ret = uvc_query_ctrl(dev  /* һUSB豸 */, SET_CUR, ctrl->entity->id  /* һunit/terminal */,
                				dev->intfnum /* һӿ: VC interface */, ctrl->info->selector,
                				uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
                				ctrl->info->size);
3. VideoStreaming InterfaceڻƵݣҲѡfromat/frame(VSжformat, һformatֶ֧frame frameʾֱʵϢ)
   ͨƵĺʣ
                    	ret = __uvc_query_ctrl(video->dev /* һUSB豸 */, SET_CUR, 0,
                    		video->streaming->intfnum  /* һӿ: VS */,
                    		probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, data, size,
                    		uvc_timeout_param);
4. FORMATʱֻǼ򵥵ʹvideo->streaming->format[fmt->index]ݣ
   Щģ
   Ӧ豸öʱõģҲǷʱõġ

5. UVCصڣ
   ķ
   ԵĿ: ͨVideoControl Interface
   ʽѡͨVideoStreaming Interface
   ݵĻãͨVideoStreaming InterfaceURB

дUVC֮

ߡдUVC֮ʵݴ
A. ubuntuӴ0printkϢ
a. vmwareserial port, ʹļΪ
b. ubuntu޸/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"

sudo update-grub
sudo reboot

c. ubuntuֹrootû¼
޸root: sudo passwd root
Ȼִ"su root"Ϳroot¼

d. echo "8 4 1 7" > /proc/sys/kernel/printk

ٴֻҪִ2Ϳԣ
su root
echo "8 4 1 7" > /proc/sys/kernel/printk

B. д룺
1.һusb_driver
2.
   probe:
        2.1. video_device:video_device_alloc
        2.2. 
           .fops
           .ioctl_ops (Ҫ11)
           ҪںṩĻҪһvideobuf_queue_ops
        2.3. ע: video_register_device      
  id_table: ʾ֧ЩUSB豸      
3.ע᣺ usb_register
 
USBͷͺ:
a. Ƶõ:  6190 ,ԭʼYUVݣ֧MJPEGѹ
   35Ԫ
b. ҲʹUVC淶ͷ: ǽӵWINDOWSϺװͷ
   ҪдҪͨ
c. Ҳһͷ, 2ӿڣUSBCMOS(ITU-R BT. 601/656)
   ֧MJPEGʽ, , 2013820һ100ask.taobao.com
   100Ԫ
   , һ¼һƵֳ޸Ĵ

ע⣺ʹ֧MJPEGʽͷҲĿƵʵ飬
      ֻǽԶƵʱҪͼѹƵЩ


ˡдUVC֮ʵ()
1. ȿAPPȷҪʵЩӿ
xawtv.c:
    grabber_scan
        ng_vid_open
            v4l2_driver.open // v4l2_open
                get_device_capabilities(h);
                    // VIDIOC_QUERYCTRL ioctlȷǷ֧ĳ
                    /* controls */
                    for (i = 0; i < MAX_CTRL; i++) {
                	h->ctl[i].id = V4L2_CID_BASE+i;
                	if (-1 == xioctl(h->fd, VIDIOC_QUERYCTRL, &h->ctl[i], EINVAL) ||
                	    (h->ctl[i].flags & V4L2_CTRL_FLAG_DISABLED))
                	    h->ctl[i].id = -1;
                    }
ôȥ/ԣ
drv0-v4l2.c
ɼ2:
v4l2_read_attr  : VIDIOC_G_CTRL
v4l2_write_attr : VIDIOC_S_CTRL

: ƵҪʵ3ioctl:
VIDIOC_QUERYCTRL
VIDIOC_G_CTRL
VIDIOC_S_CTRL


2. Ӳô?
2.1 UVC淶ﶨЩ : uvc_ctrl.c: static struct uvc_control_info uvc_ctrls[]

	{
		.entity		= UVC_GUID_UVC_PROCESSING, // ˸entity(PU)
		.selector	= PU_BRIGHTNESS_CONTROL,   // 
		.index		= 0,                       // ӦProcessing Unit DescriptorbmControls[0]
		.size		= 2,                       // ݳΪ2ֽ
		.flags		= UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
				| UVC_CONTROL_RESTORE,
	},


 
2.2 ǵ豸֧Щ
    Ҫȥ,  Processing Unit DescriptorbmControlsֵΪ7f 14
    ֪BIT0Ϊ1ʾ֧BRIGHTNESS
    
    ڴ
uvc_drvier.c
uvc_ctrl_init_device    
    // ÿһentity(IT,PU,SU,OT)
	list_for_each_entry(entity, &dev->entities, list) {
	    // ȡbmControls
	    bmControls = ....
	    
	    // bmControlsλֵΪ1ĸֵ֧Ը
	    ncontrols += hweight8(bmControls[i]);    
	    
	    // ΪÿһԷһstruct uvc_control
	    entity->controls = kzalloc..
	    
	    // Щstruct uvc_control
	    ctrl = entity->controls;
	    for (...)
	    {
    		ctrl->entity = entity;
    		ctrl->index = i;
		}

        // uvc_controluvc_control_infoҹ
        uvc_ctrl_add_ctrl(dev, info);
            ctrl->info = ĳuvc_control_info(ͬһentity, indexͬ)

2.3 ôȥЩ
    ο uvc_query_v4l2_ctrl
    uvc_find_control
        ҵһuvc_control_mappingṹ: uvc_ctrl.cstatic struct uvc_control_mapping uvc_ctrl_mappings[] 
        	{
        		.id		= V4L2_CID_BRIGHTNESS,  // APPIDҵӦ
        		.name		= "Brightness",
        		.entity		= UVC_GUID_UVC_PROCESSING,  // ˸entity(PU)
        		.selector	= PU_BRIGHTNESS_CONTROL,    // 
        		.size		= 16,                       // ռλ
        		.offset		= 0,                        // λʼ
        		.v4l2_type	= V4L2_CTRL_TYPE_INTEGER,   // 
        		.data_type	= UVC_CTRL_DATA_TYPE_SIGNED,// 
        	},

         uvc_control_mappingṹ ϸµ

    uvc_query_ctrl
        usb_control_msg


˵: Ҫȣô
a. PUbmControls, bit01ֵ֪֧
b. uvc_ctrlsиentityindexҵһ
	{
		.entity		= UVC_GUID_UVC_PROCESSING,
		.selector	= PU_BRIGHTNESS_CONTROL,
		.index		= 0,
		.size		= 2,
		.flags		= UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
				| UVC_CONTROL_RESTORE,
	},

֪ˣ豸֧SET_CUR, GET_CUR, GET_MIN
ҪʱPUselector, 2ֽ

c. uvc_ctrl_mappingsиIDҵӦ
   Ӷ֪˸ϸµϢ
   Ȼʹusb_control_msgд
   

3. ôд룿
ʵ3ioctl: vidioc_queryctrl/vidioc_g_ctrl/vidioc_s_ctrl
vidioc_queryctrl : USBƴȵСֵֵĬֵֵ
vidioc_s_ctrl    : APPֵͨUSB䷢Ӳ
vidioc_g_ctrl    : USBõǰֵ

Ҫ㣺ݷ˭usb_device
                          VideoControl Interface
                                    Processing Unit 
                                            PU_BRIGHTNESS_CONTROL

. PCϰUSBͷ: ޸PC LINUXUVC
ʮ. "дUVC"޸, ֧ͷ
ʮһ. ޸ĿϵUVC, LCDʾͷͼ
(1)׼
1. ׼
2װ
sudo tar xjf arm-linux-gcc-4.3.2.tar.bz2 -C /
û
sudo vi /etc/environment   PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/arm/4.3.2/bin"

3. ں
tar xjf linux-3.4.2.tar.bz2
cd linux-3.4.2

ʹõĲ: 
linux-3.4.2_camera_jz2440.patch
linux-3.4.2_camera_mini2440.patch
linux-3.4.2_camera_tq2440.patch

patch -p1 < ../linux-3.4.2_camera_jz2440.patch
cp config_ok .config
make uImage

ҲԴӱҵں˲Լ޸ġ:
patch -p1 < ../linux-3.4.2_100ask.patch

 lcd_4.3.c Ƶ /work/projects/linux-3.4.2/drivers/video
޸/work/projects/linux-3.4.2/drivers/video/Makefile
#obj-$(CONFIG_FB_S3C2410)         += s3c2410fb.o
obj-$(CONFIG_FB_S3C2410)          += lcd_4.3.o

dm9dev9000c.cdm9000.hƵ/work/projects/linux-3.4.2/drivers/net/ethernet/davicom
޸/work/projects/linux-3.4.2/drivers/net/ethernet/davicom/Makefile

cp config_ok .config
make menuconfig
   <*> Multimedia support  --->
       <*>   Video For Linux 
       [*]   Video capture adapters (NEW)  --->
              [*]   V4L USB devices (NEW)  --->
                   <*>   USB Video Class (UVC) 

// ʹõǰƵUSBͷ
// Ҫο21.1.9Ƶ޸UVC
                   
make uImae


cp arch/arm/boot/uImage /work/nfs_root/uImage_new
 
4. ļϵͳ
cd /work/nfs_root
sudo tar xjf fs_mini_mdev_new.tar.bz2
sudo chown book:book fs_mini_mdev_new

5. ںˡļϵͳ
UBOOT
UBOOTĻ
set ipaddr 192.168.1.17
set bootcmd 'nfs 32000000 192.168.1.124:/work/nfs_root/uImage_new; bootm 32000000'
set bootargs console=ttySAC0,115200 root=/dev/nfs nfsroot=192.168.1.124:/work/nfs_root/fs_mini_mdev_new ip=192.168.1.17
save 
boot

(2)д
(3)Բ
a. ɹ
b. ٲ

(4) PCʾ
ִʱҲlibvga⣬²
sudo cp /usr/local/lib/libvga* /lib -d


οĵ:
http://www.svgalib.org/jay/beginners_guide/beginners_guide.html

ʮ. LCDʾͷͼ
ʮ. дCMOS
ʮ. ĿЯʽ߼

ʮ. ʹWIFI
1. ׼(,)ںѡWIFI
1.1 ѡͣȷVID,PIDǷб:http://wireless.kernel.org/en/users/Devices/USB
ѡWIFI
Atheros : VID 0x13D3  PID 0x3327 (Ʒͺ AR9271)
realtek : VID 0x0bda  PID 0x8176 (ƷͺTP-LINK˾TL-WN721N)

1.2 
a. VMWAREΪŽ, ѡʹһ
b. PC windows, vmware linuxIPΪ192.168.7.xxx
   ΪԺ󿪷USB WIFIʹ192.168.1.xxx

1.3 ں֧USB WIFI
a. 򲹶
tar xjf linux-3.4.2.tar.bz2
cd linux-3.4.2
patch -p1 < ../linux-3.4.2_camera_mini2440.patch 
cp config_ok .config

b. ں: VID/PIDȷʹһԴ
             ԴĿ¼Makefileȷ
             make menuconfig, /

cd drivers/net/wireless/
grep "0x3327" * -nR
ath/ath9k/hif_usb.c:32: { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */
ath/ath9k/Makefile֪Ϊ CONFIG_ATH9K_HTC
make menuconfig, /CONFIG_ATH9K_HTC õϢ
Symbol: ATH9K_HTC [=n]                                                                     |
  | Type  : tristate                                                                           |
  | Prompt: Atheros HTC based wireless cards support                                           |
  |   Defined at drivers/net/wireless/ath/ath9k/Kconfig:100                                    |
  |   Depends on: NETDEVICES [=y] && WLAN [=y] && ATH_COMMON [=n] && USB [=y] && MAC80211 [=m] |
  |   Location:                                                                                |
  |     -> Device Drivers                                                                      |
  |       -> Network device support (NETDEVICES [=y])                                          |
  |         -> Wireless LAN (WLAN [=y])                                                        |
  |           -> Atheros Wireless Cards (ATH_COMMON [=n])

:
-> Networking suppor
  -> Wireless 
    <*>   cfg80211 - wireless configuration API
    <*>   Generic IEEE 802.11 Networking Stack (mac80211)
-> Device Drivers
  -> Network device support
    -> Wireless LAN
      -> Atheros Wireless Cards
        <*>   Atheros HTC based wireless cards support          
make uImage

һ
cd drivers/net/wireless/
grep "0x8176" * -nR
rtlwifi/rtl8192cu/sw.c:273:     {RTL_USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8176, rtl92cu_hal_cfg)},
rtlwifi/rtl8192cu/MakefileȷΪ  CONFIG_RTL8192CU
make menuconfig, /CONFIG_RTL8192CU

-> General setup
    [*] Prompt for development and/or incomplete code/drivers
-> Device Drivers 
  -> Network device support
    -> Wireless LAN  
    <*>   Realtek RTL8192CU/RTL8188CU USB Wireless Network Adapter        

make uImage

uboot:
set bootargs console=ttySAC0,115200 root=/dev/nfs nfsroot=192.168.7.124:/work/nfs_root/fs_mini_mdev_new ip=192.168.7.17
set bootcmd 'nfs 32000000 192.168.7.124:/work/nfs_root/uImage_mini2440_wifi; bootm 32000000'
save
boot
    
c. 롢ʹ
c.1 ѹ̼htc_9271.fwŵ/lib/firmware
    USB, ifconfig wlan0 up

c.2 "realtek : VID 0x0bda  PID 0x8176 (ƷͺTP-LINK˾TL-WN721N)"
޸bug:    
http://lkml.indiana.edu/hypermail/linux/kernel/1301.2/00465.html
make uImage


2. ʹWIFI: iw, wpa_supplicant,dhcp
2.1 : ֤/
߼ܵĶַ(WEP WPA TKIP EAP)
http://wenku.baidu.com/link?url=DlLntlD490hAeIIbE-CO4QfAzgUC-gOTA7FCwS_XanOJMFzkyhQrFIB38ULKCcQIVFyDqqSWNWyq5kVtYAoJKjjf9pmZLu17-hVQ922WeaG

ֻWIFIȵΪ4ֳõ"֤/"
a. open
b. WEP
c. WPA(TKIP)
d. WPA2(AES)

2.2 롢ʹiw,wpa_supplicant,dhcp
a. ɹiwconfig, iw, 2"֤/": open, WEP
a.1 
tar xzf libnl-3.2.23.tar.gz
cd libnl-3.2.23/
./configure --host=arm-linux --prefix=$PWD/tmp
޸ lib/addr.c Ӻ(ںԴ)
make
make install

ѱͷļӦ÷룺
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include

cd tmp/include/libnl3
sudo cp netlink -rf /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include

ѱĿļӦ÷룺
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib

ѱĿļӦ÷NFSļϵͳlibĿ¼
/work/nfs_root/fs_mini_mdev_new/lib

a.2 
tar xjf iw-3.11.tar.bz2
cd iw-3.11/
޸Makefile:
CC = "arm-linux-gcc"
NL3xFOUND := Y
#LIBS += $(shell $(PKG_CONFIG) --libs $(NLLIBNAME))
#CFLAGS += $(shell $(PKG_CONFIG) --cflags $(NLLIBNAME))

info.cĴǰ
#define htole16(X)  (((((uint16_t)(X)) << 8) | ((uint16_t)(X) >> 8)) & 0xffff)


ʹã
iw list  // гWIFI
ifconfig wlan0 up
iw dev wlan0 scan   // ɨWIFI AP
iw wlan0 connect dswei  // ӵWIFI APdswei (open)
iw wlan0 connect dswei keys d:0:baiwenwang123 // ӵWIFI APdswei (WEP)
                            d: default, 0: 0 
ifconfig wlan0 192.168.1.55
ping 192.168.1.1

iw wlan0 disconnect

b. wpa_supplicant : 4"֤/"
b.1 ȱlibopenssl
tar xzf openssl-1.0.1d.tar.gz
cd openssl-1.0.1d/
./config shared no-asm --prefix=$PWD/tmp
޸Makefile:
CC= arm-linux-gcc
AR= arm-linux-ar $(ARFLAGS) r
RANLIB= arm-linux-ranlib
NM= arm-linux-nm
MAKEDEPPROG= arm-linux-gcc

make
make install
װ
ѱͷļӦ÷룺
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include

ѱĿļӦ÷룺
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib

ѱĿļӦ÷NFSļϵͳlibĿ¼
/work/nfs_root/fs_mini_mdev_new/lib


b.2 Ҫһļ.config
tar xzf wpa_supplicant-2.0.tar.gz 
cd wpa_supplicant-2.0/wpa_supplicant/
cp defconfig .config
޸.configһ: CONFIG_LIBNL32=y
޸Makefile:
CC=arm-linux-gcc

make
make DESTDIR=$PWD/tmp install

ʹ:
mkdir -p /var/run/wpa_supplicant
 OPEN
wpa_supplicant -B -c/etc/plaintext.conf -iwlan0
wpa_cli -iwlan0 status  // 鿴״̬
ifconfig wlan0 192.168.1.55
ping 192.168.1.1

ļΪ:
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid="dswei"
        key_mgmt=NONE
}

 WEP/WEP
wpa_supplicant -B -c/etc/wep.conf  -iwlan0
wpa_cli -iwlan0 status  // 鿴״̬
ifconfig wlan0 192.168.1.55
ping 192.168.1.1

ļ:
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid="dswei"
        key_mgmt=NONE
        wep_key0="baiwenwang123"
        wep_tx_keyidx=0
}

WPA(TKIP)
wpa_supplicant -B -c/etc/wpa-psk-tkip.conf  -iwlan0
wpa_cli -iwlan0 status  // 鿴״̬
ifconfig wlan0 192.168.1.55
ping 192.168.1.1

ļ
ctrl_interface=/var/run/wpa_supplicant  # һĿ¼,wpa_supplicantwpa_clisocketͨ
network={
        ssid="dswei"
        proto=WPA  # proto: list of accepted protocols, ȡWPA,RSN
                   # If not set, this defaults to: WPA RSN
        key_mgmt=WPA-PSK # ֤ʽ
                         # If not set, this defaults to: WPA-PSK WPA-EAP
        pairwise=TKIP    # If not set, this defaults to: CCMP TKIP
        group=TKIP       # If not set, this defaults to: CCMP TKIP WEP104 WEP40 
        psk="baiwenwang12"
}

 WPA2(AES)
wpa_supplicant -B -c/etc/wpa_wpa2.conf  -iwlan0
wpa_cli -iwlan0 status  // 鿴״̬
ifconfig wlan0 192.168.1.55
ping 192.168.1.1

ļ
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid="dswei"
        psk="baiwenwang123"
}


wpa_cliɹ"ģʽ""ģʽ"

 ļönetwork:
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid="dswei"
        psk="baiwenwang123"
}
network={
        ssid="Programer"
        psk="baiwenwang"
}

 
޸/etc/resolv.confDNS:
nameserver 192.168.1.1

:
route add default gw 192.168.1.1



c. dhcp : ʹWIFI̬ȡIP
c.1 롢װ
tar xzf dhcp-4.2.5-P1.tar.gz
cd dhcp-4.2.5-P1
./configure --host=arm-linux ac_cv_file__dev_random=yes

cd bind
޸Makefile:
./configure BUILD_CC=gcc ac_cv_file__dev_random=yes --host=arm-linux --disable-kqueue

tar xzf bind.tar.gz
cd bind-9.8.4-P2
޸ lib/export/dns/Makefile.in 
gen: ${srcdir}/gen.c
        ${CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ${srcdir}/gen.c ${LIBS}
Ϊ
gen: ${srcdir}/gen.c
        ${BUILD_CC} ${ALL_CFLAGS} ${LDFLAGS} -o $@ ${srcdir}/gen.c ${LIBS}

cd ../..
make DESTDIR=$PWD/tmp install

ļƵNFS
sudo cp bin/* /work/nfs_root/fs_mini_mdev_new/bin/
sudo cp sbin/* /work/nfs_root/fs_mini_mdev_new/sbin/
sudo cp etc/dhclient.conf.example //work/nfs_root/fs_mini_mdev_new/etc/dhclient.conf
sudo cp etc/dhcpd.conf.example //work/nfs_root/fs_mini_mdev_new/etc/dhcpd.conf

sudo cp client/scripts/linux /work/nfs_root/fs_mini_mdev_new/etc/dhclient-script
chmod +x /work/nfs_root/fs_mini_mdev_new/etc/dhclient-script
޸
#!/bin/bash
Ϊ
#!/bin/sh


c.2 ʹã
mkdir -p /var/db
wpa_supplicant -B -c/etc/wpa_wpa2.conf  -iwlan0
dhclient wlan0

c.2 һWIFIԶִwpa_supplicant
ο2Ƶ28Ȱβ
cat /etc/mdev.conf 
wlan0 0:0 777 * /sbin/auto_wifi.sh

cat /sbin/auto_wifi.sh
#!/bin/sh
if [ $ACTION = "add" ];
then                                              
   wpa_supplicant -B -c/etc/wpa_wpa2.conf  -iwlan0
   wpa_cli -a/sbin/wpa_action.sh -B
else                     
   killall wpa_supplicant
   killall wpa_cli 
   killall dhclient
fi

chmod +x /sbin/auto_wifi.sh 

    һWIFI AP, Զִdhclient
һű:    
cat /sbin/wpa_action.sh 
#!/bin/sh
IFNAME=$1
CMD=$2
if [ "$CMD" = "CONNECTED" ]; then
   echo connect $IFNAME, dhclient for it > /dev/console
   dhclient $IFNAME
fi
if [ "$CMD" = "DISCONNECTED" ]; then
   echo disconnect $IFNAME, kill dhclient for it > /dev/console
   killall dhclient
fi

chmod +x /sbin/wpa_action.sh

wpa_cli -a/sbin/wpa_action.sh -B


3. ʹWIFIAP

ο: ֲhostapdȵ - ˮԨ - Ƶ - CSDN.NET.htm
http://blog.csdn.net/daydring/article/details/16337047

3.1 Դ: http://w1.fi/hostapd/
3.2 롢װ
tar xzf hostapd-2.0.tar.gz
cd hostapd-2.0/
cd hostapd/
cp defconfig .config
޸.config, һ: CONFIG_LIBNL32=y
޸Makefile:
CC=arm-linux-gcc
make
make DESTDIR=$PWD/tmp install

ɵhostapd  hostapd_cliƵNFSbinĿ¼

3.3 ʹ
a. hostapdļ: WPA/WPA2
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel=1

# ֤/ܷʽ
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=baiwenwang
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

ļΪ/etc/myhostapd.conf
 hostapd: hostapd -B /etc/myhostapd.conf

b.  dhcpd
޸ļ/etc/dhcpd.confӣ
subnet 192.168.1.0 netmask 255.255.255.0 {                       
  range 192.168.1.10 192.168.1.100;                              
  option domain-name-servers 192.168.1.1;                        
  option routers 192.168.1.1;                                    
}    

ļ/var/db/dhcpd.leases:
> /var/db/dhcpd.leases

ifconfig wlan0 192.168.1.1
dhcpd -cf /etc/dhcpd.conf wlan0


3.4 OPENʽļ
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel=1

# ֤/ܷʽ
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0

3.5 WEPʽļ
ctrl_interface=/var/run/hostapd
#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=S3C2440
channel=1

# ֤/ܷʽ
macaddr_acl=0
auth_algs=2
ignore_broadcast_ssid=0
wep_key0="baiwenwang123"
wep_default_key=0

3.6 ޸/etc/mdev.confԶAPģʽ
cat /etc/mdev.conf 
wlan0 0:0 777 * /sbin/auto_wifi_ap.sh

cat /sbin/auto_wifi_ap.sh 
#!/bin/sh
if [ $ACTION = "add" ]; 
then
   hostapd -B /etc/myhostapd.conf
   ifconfig wlan0 192.168.1.1
   dhcpd -cf /etc/dhcpd.conf wlan0
else
   killall hostapd
   killall dhcpd
fi

ע:
ڰAR9271ںˣһ⣺
ϵ֮ǰͽôϵͳ޷ʶ

1ϵٽ
2Ϊģ飬ϵͳinsmod ϵ֮ǰͽ

ԭath9k_htc.koҪõ̼, ǹ̼Ҫļϵͳغܷ

4. ֻдһWIFI
⼸:
a. ԶɨWIFIȵ
b. ĳWIFIȵȥ, Ҫʱ
c. ӹWIFIȵᱣϢ, ԺԶ

wpa_supplicant  <===== wpa_cli
wpa_cli, wpa_supplicant, :
scan
add_network, set_network, select_network
save_config

ģwpa_cli ͨ wpa_request  wpa_supplicant õ


5. WIFI(Ҳѧϰ,ⲿӺ)




ʮʹ3G(Ϊ3G modem)
1. ʹ:
1.1 ѡͣ
йͨEʱ EW65 (64Ԫ), ZTE MF637U (160)
йţBenton/ EQ10B (35Ԫ)
йƶΪ ET128 (99Ԫ), ҪZTE A371(Linux²֧)

ͺſɲο: usb_modeswitchdevice_reference.txt

1.2 ʹò(windowsΪ)
a. ϷƶӲ̣аװ
b. װƶӲʧ
c. ӲԶװ󣬷2ںһmodem
d. г򼴿ɲ

zeroCD: 3GԴ,ӵPCΪƶӲʹ,װлΪmodem

Linuxʹụ̀
a. Ϻлmode: usb_modeswitch
b. װ: linuxںԴ, 3ttyUSB0,1,2
c. pppd

1.3 Ӧó򲢲
ں
-> Device Drivers
  -> Network device support
	       <*>   PPP (point-to-point protocol) support                                
  				    <*>     PPP BSD-Compress compression                                  
              <*>     PPP Deflate compression                                               
              [*]     PPP filtering                                                     
              <*>     PPP MPPE compression (encryption) (EXPERIMENTAL)                  
              [*]     PPP multilink support (EXPERIMENTAL)                              
              <*>     PPP over Ethernet (EXPERIMENTAL)                                  
              <*>     PPP support for async serial ports                                
              <*>     PPP support for sync tty ports   
-> Device Drivers
  -> USB support
     <M>   USB Serial Converter support  	
       	  <M>   USB driver for GSM and CDMA modems

make uImage && make modules

ӦóԴ:
http://www.draisberghof.de/usb_modeswitch/
http://www.libusb.org/
ftp://ftp.samba.org/pub/ppp/

:
libusb:
./configure --host=arm-linux --prefix=$PWD/tmp
make 
make install
ͷļͿ⸴ƽ湤
sudo  cp libusb.h /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
sudo cp * -rfd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib

ѿ⸴ƵļϵͳlibĿ¼
sudo cp *so* -d /work/nfs_root/fs_mini_mdev_new/lib/

usb_modeswitch:
޸Makefile
CC          = arm-linux-gcc
LIBS        = -lusb-1.0

make DESTDIR=$PWD/tmp
make DESTDIR=$PWD/tmp  install

cd tmp
sudo cp * -rfd /work/nfs_root/fs_mini_mdev_new

usb-modeswitch-data-20131113:
make DESTDIR=$PWD/tmp install
cd tmp
sudo cp * -rfd /work/nfs_root/fs_mini_mdev_new

pppd:
޸6ļ, "$(INSTALL) -s"Ϊ"$(INSTALL) "
chat/Makefile.linux
pppd/plugins/radius/Makefile.linux
pppd/plugins/rp-pppoe/Makefile.linux
pppd/Makefile.linux
pppdump/Makefile.linux
pppstats/Makefile.linux

./configure --host=arm-linux --prefix=$PWD/tmp
make CC=arm-linux-gcc
make CC=arm-linux-gcc install
cd tmp
sudo cp * -rfd /work/nfs_root/fs_mini_mdev_new

ʹã
A. mf637Ϊ
ο HI3515˼ֲ3Gģʼ - ǿ - Ƶ - CSDN.NET.htm
http://blog.csdn.net/alangdangjia/article/details/9413009
a. ں
   : sudo cp drivers/usb/serial/*.ko /work/nfs_root/fs_mini_mdev_new
b. 3Glsusb鿴VID/PID
lsusb
Bus 001 Device 002: ID 19d2:2000

c. ʹusb_modeswitchлģʽ   
ҪһļʹõVIP/PIDdevice_reference.txtҵһֵ
дһļmf637.cfg
ŵ/etcĿ¼
usb_modeswitch -c /etc/mf637.cfg

d. װ
insmod usbserial.ko
insmod usb_wwan.ko 
insmod option.ko

e. pppd
mf637:
޸/etc/ppp/peers/wcdma-dailer, ʹ/dev/ttyUSB2
pppd call wcdma-dailer &
cp /etc/ppp/resolv.conf /etc/resolv.conf
ping news.qq.com

B. EW65Ϊ
device_refeence.txtѡȡһδΪew65.cfg
ϽEW65ִУusb_modeswitch -c /etc/ew65.cfg
޸/etc/ppp/peers/wcdma-dailer, ʹ/dev/ttyUSB0
pppd call wcdma-dailer &
cp /etc/ppp/resolv.conf /etc/resolv.conf
ping news.qq.com

C. йţBenton/ EQ10B (35Ԫ)
device_refeence.txtѡȡһδΪeq10b.cfg
ϽEQ10BִУusb_modeswitch -c /etc/eq10b.cfg
޸/etc/ppp/peers/evdo-dailer, ʹ/dev/ttyUSB0
pppd call evdo-dailer &
cp /etc/ppp/resolv.conf /etc/resolv.conf
ping news.qq.com

D. йƶ ET128
device_refeence.txtѡȡһδΪet128.cfg
ϽEQ10BִУusb_modeswitch -c /etc/et128.cfg

ο
http://wenku.baidu.com/link?url=pVNn9okBYfUAHiNDBdtpGXselQ9uYVj1lKL5WPmEYaOpMawiYamLrtRcdRZgy5LslcPQL28ySW7q282o1VdBqciHZmsjaRsQ5Xj97oYDqce

ںˣ
-> Device Drivers
  -> USB support
    <M>   USB Modem (CDC ACM) support 

sudo cp drivers/usb/class/cdc-acm.ko /work/nfs_root/fs_mini_mdev_new/

ls /dev/ttyACM*
/dev/ttyACM0  /dev/ttyACM1  /dev/ttyACM2

޸td-dailerű:
http://wenku.baidu.com/link?url=pVNn9okBYfUAHiNDBdtpGXselQ9uYVj1lKL5WPmEYaOpMawiYamLrtRcdRZgy5LslcPQL28ySW7q282o1VdBqciHZmsjaRsQ5Xj97oYDqce

pppd call td-dailer &

2. дƳԶʹøͺ3G
a. usb_modeswitch -c /etc/...  // 1. ڲͬ3GϢһ
b. insmod ...
c. pppd call wcdma-dailer      // 2. ڲͬ3Gʹòͬ/dev/ttyUSB
   pppd call evdo-dailer
   pppd call td-dailer

дһƳ:
a. 3Gusb_modeswitchṩӦϢ
b. ʶ/dev/ttyUSB..., һļ/dev/gsmmodemָ򲦺ʱҪõ/dev/ttyUSB

οPC϶3Gʶ̣
PCϱ롢װ: libusb-1.0.9.tar.bz2, usb-modeswitch-2.0.1.tar.bz2, usb-modeswitch-data-20131113.tar.bz2, ppp-2.4.5.tar.gz

USB 3G
PC:
a. /lib/udev/rules.d/40-usb_modeswitch.rules֪
   3Gִ: usb_modeswitch '%b/%k'
   ִеǣ/lib/udev/usb_modeswitch
   ֻ/usr/sbin/usb_modeswitch_dispatcher
b. /usr/sbin/usb_modeswitch_dispatcherusb_modeswitchģʽл
   :/usr/sbin/usb_modeswitch -W -D -s 20 $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$configBuffer"
   ʹļ,ʹ-f, Щ/usr/share/usb_modeswitch
   /usr/share/usb_modeswitchڶļ"vid:pid"Ϊ

   /usr/sbin/usb_modeswitch_dispatcher3Gvid,pidҵ/usr/share/usb_modeswitchļ,
   ȻִУusb_modeswitch -V vid -P pid -f "ļ"
c. ôļ/dev/gsmmodem:
# The facility to add a symbolic link pointing to the
# ttyUSB port which provides interrupt transfer, i.e.
# the port to connect through.
# Will check for interrupt endpoint in ttyUSB port (lowest if
# there is more than one); if found, return "gsmmodem[n]" name
# to udev for symlink creation
/dev/gsmmodemָһ/dev/ttyUSBX, /dev/ttyUSBXӦinterface"ж͵Ķ˵"
ж/dev/ttyUSBXжͶ˵, /dev/gsmmodemָС/dev/ttyUSBX

ôжttyUSBжͶ˵㣺
# In case the device path is returned as /sys/class/tty/ttyUSB,
# get the USB device path from linked tree "device"
/* 1. ÿһ/dev/ttyUSBX
 *    һӦ/sys/class/tty/ttyUSBX
 * 2. һļ, ָ: /sys/......../1-1:1.0/ttyUSB0/tty/ttyUSB0
 * 3. /sys/......../1-1:1.0/Ŀ¼,
 *    ж"ep_"Ŀ¼
 * 4. Ŀ¼Ϊtypeļ
 * 5. ļΪInterrupt, 򷵻1
 *    
 */



ο:
ǶʽLinux3G USB Modemʹ - ֮켣Լ - Ƶ - CSDN.NET.htm
http://blog.csdn.net/ling1874/article/details/8148822
http://wenku.baidu.com/link?url=HLRk3U9Jbr2Zx35e5knamYeUKYs14bhV3F9-hzC6rWMwdxCu2gTtAR89VBAdpoAF4UC9LmxCPxGLbjAu_XoSXuy065ZbbvfwtWm9vLy5UWe

ļȫ
HI3515˼ֲ3Gģʼ - ǿ - Ƶ - CSDN.NET.htm
http://blog.csdn.net/alangdangjia/article/details/9413009

£pppusb_modeswitchȹֲ˵_ٶĿ.htm
http://wenku.baidu.com/link?url=Y7gsW5izmXwzur3VS3hGYWV_k_glZwzmu7Prdh_F69LuFxcOGT1LwhtsmXA3TVhR6F0l8_ozspcQvO08nlHex2yss0EW7wWIzysw9cZn-wu














1. http://www.draisberghof.de/usb_modeswitch/
   http://www.libusb.org/

wvdial armֲʼ .-UP-NETARM2410-ChinaUnix.htm
http://blog.chinaunix.net/uid-20759926-id-3337026.html

wvdial:
http://alumnit.ca/wiki/index.php?page=WvDial

How to interface USB modem to ARM board (for android or linux) 
http://embeddlinux.blogspot.com/2013/01/how-to-interface-usb-modem-to-arm-board.html


ǶʽLinux3Gֲ
http://www.embeddedlinux.org.cn/html/yingjianqudong/201303/15-2489.html

pppd
ftp://ftp.samba.org/pub/ppp/


ǶʽLinux3G USB Modemʹ - ֮켣Լ - Ƶ - CSDN.NET.htm
http://blog.csdn.net/ling1874/article/details/8148822
http://wenku.baidu.com/link?url=HLRk3U9Jbr2Zx35e5knamYeUKYs14bhV3F9-hzC6rWMwdxCu2gTtAR89VBAdpoAF4UC9LmxCPxGLbjAu_XoSXuy065ZbbvfwtWm9vLy5UWe

ļȫ
HI3515˼ֲ3Gģʼ - ǿ - Ƶ - CSDN.NET.htm
http://blog.csdn.net/alangdangjia/article/details/9413009

£pppusb_modeswitchȹֲ˵_ٶĿ.htm
http://wenku.baidu.com/link?url=Y7gsW5izmXwzur3VS3hGYWV_k_glZwzmu7Prdh_F69LuFxcOGT1LwhtsmXA3TVhR6F0l8_ozspcQvO08nlHex2yss0EW7wWIzysw9cZn-wu

udev-ChinaUnixϵͳƵ.htm
http://os.chinaunix.net/a2008/0626/982/000000982085.shtml


Linux USB FAQ.htm
http://www.linux-usb.org/FAQ.html

lsusb
https://www.kernel.org/pub/linux/utils/usb/usbutils/

/lib/udev/usb_modeswitch /1-1
if [ -e "/etc/init/usb-modeswitch-upstart.conf" ]; then
        exec /sbin/initctl emit --no-wait usb-modeswitch-upstart UMS_PARAM=$1
        
/usr/sbin/usb_modeswitch_dispatcher --switch-upstart /1-1
/sbin/initctl emit --no-wait usb-modeswitch-upstart UMS_PARAM=/1-1

/usr/sbin/usb_modeswitch_dispatcher --switch-mode $1

/usr/sbin/usb_modeswitch -W -D -s 20 -u -1 -b 1 -g 7 -v 19d2 -p 2000 -f # ZTE devices TargetVendor= 0x19d2 TargetProductList="0001,0002,0015,0016,0017,0019,0031,0037,0052,0055,0061,0063,0064,0066,0091,0108,0117,0128,0157,0177,1402,2002,2003" MessageContent="5553424312345678000000000000061e000000000000000000000000000000" MessageContent2="5553424312345679000000000000061b000000020000000000000000000000" MessageContent3="55534243123456702000000080000c85010101180101010101000000000000" NeedResponse=1

# The facility to add a symbolic link pointing to the
# ttyUSB port which provides interrupt transfer, i.e.
# the port to connect through.
# Will check for interrupt endpoint in ttyUSB port (lowest if
# there is more than one); if found, return "gsmmodem[n]" name
# to udev for symlink creation

# This is run once for every port of LISTED devices by
# an udev rule


# In case the device path is returned as /class/tty/ttyUSB,
# get the USB device path from linked tree "device"



luvcviewarmϵֲ 
http://blog.chinaunix.net/uid-20364597-id-3507440.html


[*] Networking support  ---> 
			-*-   Wireless  --->
				<*>   cfg80211 - wireless configuration API
				[*]     cfg80211 wireless extensions compatibility 
				<*>   Generic IEEE 802.11 Networking Stack (mac80211)

Device Drivers  --->
	[*] Network device support  ---> 
		[*]   Wireless LAN  --->
			<*>   Atheros Wireless Cards  ---> 
				<*>   Atheros HTC based wireless cards support				


usb 1-1: new full-speed USB device number 4 using s3c2410-ohci
usb 1-1: ath9k_htc: Firmware htc_9271.fw requested
usb 1-1: ath9k_htc: Failed to get firmware htc_9271.fw
usb 1-1: ath9k_htc: USB layer deinitialized

mkdir /lib/firmware
 htc_9271.fw ŵ /lib/firmware

usb 1-1: USB disconnect, device number 4
usb 1-1: new full-speed USB device number 5 using s3c2410-ohci
usb 1-1: ath9k_htc: Firmware htc_9271.fw requested
usb 1-1: ath9k_htc: Transferred FW: htc_9271.fw, size: 51272
ath9k_htc 1-1:1.0: ath9k_htc: HTC initialized with 33 credits
ath9k_htc 1-1:1.0: ath9k_htc: FW Version: 1.3
ieee80211 phy0: Atheros AR9271 Rev:1

ifconfig wlan0 up
ifconfig  // ɼwlan0


wpa_supplicant ֲ linux ģʽ
http://www.cnblogs.com/wanhl/p/3374443.html

FS2410wpa_supplicantֲ
http://www.linuxidc.com/Linux/2011-10/45202.htm

iw:
kernel.org/pub/software/network/iw/
: iw-3.11.tar.bz2
tar xjf iw-3.11.tar.bz2
cd iw-3.11/
make


tar xzf libnl-3.2.23.tar.gz 
cd libnl-3.2.23/
./configure --host=arm-linux --prefix=$PWD/tmp
make // ޸lib/addr.cӺ
make install


wpa_supplicant-2.0:
http://www.cnblogs.com/wanhl/p/3374443.html

cd wpa_supplicant-2.0/wpa_supplicant
cp defconfig .config
.configһ"CONFIG_LIBNL32=y"
make
make install DESTDIR=$PWD/tmp

openssl:
http://www.openssl.org/
http://www.openssl.org/source/
tar xzf openssl-1.0.1d.tar.gz
cd openssl-1.0.1d/
./config shared no-asm --prefix=$PWD/tmp
޸Makefile:
CC= arm-linux-gcc
AR= arm-linux-ar $(ARFLAGS) r
RANLIB= arm-linux-ranlib
MAKEDEPPROG= arm-linux-gcc

make
make install




iwiwconfig
http://blog.csdn.net/jincheng121/article/details/8129421


wpa_supplicant -B -d -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf
wpa_supplicant -B -d -iwlan0 -c/etc/wpa_supplicant.conf

wpa_cli -iwlan0 status

ifconfig wlan0 192.168.1.55
route add default gw 192.168.1.1


cat /etc/resolv.conf 
nameserver 192.168.1.1


޸BUGhttp://lkml.indiana.edu/hypermail/linux/kernel/1301.2/00465.html


USB_DEVICE(0x2001, 0x3306)
drivers/staging/rtl8712/usb_intf.c
: CONFIG_R8712U

Device Drivers
	[*] Staging drivers  --->
		<*>   RealTek RTL8712U (RTL8192SU) Wireless LAN NIC driver 
̼: http://mirrors.arizona.edu/raspbmc/downloads/bin/lib/wifi/rtlwifi/
 

DLINK: ޸
CONFIG_RTL8192CU

General setup  --->
	[*] Prompt for development and/or incomplete code/drivers

Device Drivers  --->
	[*] Network device support  ---> 
		[*]   Wireless LAN  --->
			<*>   Realtek RTL8192CU/RTL8188CU USB Wireless Network Adapter

http://www.realtek.com/downloads/downloadsView.aspx?Langid=2&PNid=21&PFid=48&Level=5&Conn=4&ProdID=277&DownTypeID=3&GetDown=false&Downloads=true

GOOGLErtl8192cufw.bin,ŵ:
/lib/firmware/rtlwifi/rtl8192cufw.bin



cat /etc/wpa_supplicant.conf 
#WPA-PSK/TKIP
ctrl_interface=/var/run/wpa_supplicant
network={
    ssid="dswei"
    proto=WPA RSN     # proto: list of accepted protocols
    key_mgmt=WPA-PSK  # key_mgmt: list of accepted authenticated key management protocols
    pairwise=CCMP     # pairwise: list of accepted pairwise (unicast) ciphers for WPA
    group=CCMP        # group: list of accepted group (broadcast/multicast) ciphers for WPA
    psk="baiwenwang"  # psk: WPA preshared key; 256-bit pre-shared key
}

򵥵ļ:
ctrl_interface=/var/run/wpa_supplicant
network={
    ssid="Programer"
    psk="baiwenwang"
}

߼ܵĶַ(WEP WPA TKIP EAP)
http://wenku.baidu.com/link?url=DlLntlD490hAeIIbE-CO4QfAzgUC-gOTA7FCwS_XanOJMFzkyhQrFIB38ULKCcQIVFyDqqSWNWyq5kVtYAoJKjjf9pmZLu17-hVQ922WeaG

ȫ֤ʽ֣
1. WEP
2. WPA
3. WPA2

proto=WPA RSN   (RSNWPA2)

WPA֤ʽ: WPA-PSK WPA-EAP ...
key_mgmt=WPA-PSKʱpsk, psk="readable password"  psk=..... (wpa_passphrase)
WPAļܷʽ: TKIP(WPA) CCMP(WPA2)

CCMP, AES-CCMP

802.11iʱԿЭ飨TKIP
ģʽϢ֤Э飨Counter Mode with Cipher Block Chaining Message Authentication Code Protocol C CCMP
Wireless Robust Authentication Protocol C WRAPּܷʽ
⻹һAES-CCMPܷʽAESʾAdvanced encryption standard߼ܱ׼ʹAES㷨ʱDESData Encryption Standard C ݼܱ׼㷨ܹṩߵİȫԣAES-CCMPҪӲ˳ɱ

wpa_supplicant -B -d -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf
wpa_supplicant -B -d -iwlan0 -c/etc/wpa_supplicant.conf

wpa_cli -iwlan0 status

֤
߼ܵĶַWEP WPA TKIP EAP 
İȫ֤ͼ֤
ֻ֤бɵûӵ磻
ܵĿṩݵıԺԣڴвᱻ۸ģ

93߼ܵĶַ(WEP WPA TKIP EAP)
http://3y.uu456.com/bp-cf93b8ede009581b6bd9ebd9-2.html

ļ:
1. Open System: ȫ֤Ҳܣκӵ˶߽㡣
cat /etc/wpa_supplicant.conf 
ctrl_interface=/var/run/wpa_supplicant
network={
    ssid="dswei"
#    psk="baiwenwang"
    key_mgmt=NONE
}

2. WEP:
WEP (Wired Equivalent Privacy): ߵЧЭ顣
߽趨 WEPԿ(WEP Key)Ҫ뵽ǱҪ趨ͬWEP Key
޷ӵ硣WEP֤Ǽܣ֤ʹOpen SystemʹWEP
֤ͼܶʹWEPWEPѾƽ⣬˲Ǻܰȫ

iw wlan0 connect dswei keys d:0:baiwenwang123

key must be [d:]index:data where
  'd:'     means default (transmit) key
  'index:' is a single digit (0-3)
  'data'   must be 5 or 13 ascii chars
           or 10 or 26 hex digits

wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid="dswei"
        key_mgmt=NONE
        wep_key0="baiwenwang123"
        wep_tx_keyidx=0
}

3. WPA(TKIP) : pairwiseӦΪTKIP, groupӦΪTKIP. Ĭ֧TKIP,CCMP(AES)
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid="dswei"
        psk="baiwenwang"
}   

4. WPA2(AES) : pairwiseӦΪCCMP, groupӦΪCCMP. Ĭ֧CCMP TKIP WEP104 WEP40
ctrl_interface=/var/run/wpa_supplicant
network={
        ssid="dswei"
        psk="baiwenwang"
}   

hostapd:
tar xzf hostapd-2.0.tar.gz
cd hostapd-2.0/hostapd
cp defconfig .config
vi .config   // һ: CONFIG_LIBNL32=y
vi Makefile  // CC=arm-linux-gcc
make
make install DESTDIR=$PWD/tmp
cp tmp/usr/local/bin  nfs...

ֲhostapdȵ - ˮԨ - Ƶ - CSDN.NET.htm
http://blog.csdn.net/daydring/article/details/16337047


PCִ: dhclient -v
http://www.isc.org/sw/dhcp/
: https://lists.isc.org/pipermail/dhcp-users/2013-February/016402.html
tar xzf dhcp-4.2.5-P1.tar.gz
cd dhcp-4.2.5-P1/
./configure --host=arm-linux ac_cv_file__dev_random=yes CC=arm-linux-gcc
make
make DESTDIR=$PWD/tmp install

ʹ: http://www.cfanz.cn/?c=article&a=read&id=59355


hdcpd:
http://sourceforge.net/projects/dhcpserver/files/

[585955.047776] usb 1-1: new high speed USB device using ehci_hcd and address 3
[585955.269142] usb 1-1: configuration #1 chosen from 1 choice
[585955.379843] uvcvideo: Found UVC 1.00 device USB2.0 Camera (1e4e:0102)
[585955.440427] uvcvideo: UVC non compliance - GET_DEF(PROBE) not supported. Enabling workaround.
[585955.554594] input: USB2.0 Camera as /devices/pci0000:00/0000:00:11.0/0000:02:02.0/usb1/1-1/1-1:1.0/input/input5

LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so camorama

sudo apt-get install cheese

LINUXµͷ
https://help.ubuntu.com/community/Webcam

http://blog.csdn.net/hongtao_liu/article/details/5867351
http://blog.csdn.net/hongtao_liu/article/details/5894089
V4L2Ƶ


Ƶʽ : NTSC PAL V4L2_STD_NTSC V4L2_STD_PAL
Ƶʽ RGB YCbCr 420,422 V4L2_PIX_FMT_UYVY



 
[Ƶֲ]ĵ5
http://ishare.iask.sina.com.cn/f/21425721.html
http://ishare.iask.sina.com.cn/f/21425722.html


http://www.360doc.com/content/08/0926/11/14148_1678949.shtml

ƵĻ
http://hi.baidu.com/fengbit/item/78a161375067f1c42f8ec24e

USBЭ
http://www.usb.org/developers/devclass_docs

USB Video Class Specification ʼ 
http://blog.csdn.net/chinaunixj/article/details/7394315


ǶʽLinuxƵɼϵͳ---UVCģͽ
http://blog.csdn.net/chinaunixj/article/details/7439870


Class-specific VC Interface Descriptor
e:\kernel_projects\linux-3.4.2\linux-3.4.2\include\linux\usb\Video.h
#define DECLARE_UVC_HEADER_DESCRIPTOR(n)		\
struct UVC_HEADER_DESCRIPTOR(n) {			\
	__u8  bLength;					\
	__u8  bDescriptorType;				\
	__u8  bDescriptorSubType;			\
	__u16 bcdUVC;					\
	__u16 wTotalLength;				\
	__u32 dwClockFrequency;				\
	__u8  bInCollection;				\
	__u8  baInterfaceNr[n];				\
} __attribute__ ((packed))


Input Terminal Descriptor (Camera)


ܷ
Structure of a driver
---------------------

All drivers have the following structure:

1) A struct for each device instance containing the device state.

2) A way of initializing and commanding sub-devices (if any).

3) Creating V4L2 device nodes (/dev/videoX, /dev/vbiX and /dev/radioX)
   and keeping track of device-node specific data.

4) Filehandle-specific structs containing per-filehandle data;

5) video buffer handling.

This is a rough schematic of how it all relates:

    device instances            : v4l2_device
      |
      +-sub-device instances    : v4l2_subdev
      |
      \-V4L2 device nodes       : video_device, stores V4L2 device node data, this will create the character device
	  |
	  \-filehandle instances    : v4l2_fh

The framework closely resembles the driver structure: it has a v4l2_device
struct for the device instance data, a v4l2_subdev struct to refer to
sub-device instances, the video_device struct stores V4L2 device node data
and in the future a v4l2_fh struct will keep track of filehandle instances
(this is not yet implemented).

The V4L2 framework also optionally integrates with the media framework. If a
driver sets the struct v4l2_device mdev field, sub-devices and video nodes
will automatically appear in the media framework as entities.



console/fs.h:2:20: error: FSlib.h: No such file or directory

No package 'fontsproto' found

error: asm/page.h: No such file or directory

asm/page.hΪsys/user.h

sudo apt-get install libxaw7-dev


# libraries
LDLIBS  := -lFS

./configure --x-includes=/usr/local/include/X11/fonts