usb_control_msg是没有用到urb的在USB中简单进行发送和接收的一种机制,用于少量的数据通信。原型为:

 程序代码
linux+v2.6.35/drivers/usb/core/message.c
104/**
105 * usb_control_msg - Builds a control urb, sends it off and waits for completion
106 * @dev: pointer to the usb device to send the message to
107 * @pipe: endpoint "pipe" to send the message to
108 * @request: USB message request value
109 * @requesttype: USB message request type value
110 * @value: USB message value
111 * @index: USB message index value
112 * @data: pointer to the data to send
113 * @size: length in bytes of the data to send
114 * @timeout: time in msecs to wait for the message to complete before timing
115 *      out (if 0 the wait is forever)
116 *
117 * Context: !in_interrupt ()
118 *
119 * This function sends a simple control message to a specified endpoint and
120 * waits for the message to complete, or timeout.
121 *
122 * If successful, it returns the number of bytes transferred, otherwise a
123 * negative error number.
124 *
125 * Don't use this function from within an interrupt context, like a bottom half
126 * handler.  If you need an asynchronous message, or need to send a message
127 * from within interrupt context, use usb_submit_urb().
128 * If a thread in your driver uses this call, make sure your disconnect()
129 * method can wait for it to complete.  Since you don't have a handle on the
130 * URB used, you can't cancel the request.
131 */
132int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
133                    __u8 requesttype, __u16 value, __u16 index, void *data,
134                    __u16 size, int timeout)
135{
136        struct usb_ctrlrequest *dr;
137        int ret;
138
139        dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
140        if (!dr)
141                return -ENOMEM;
142
143        dr->bRequestType = requesttype;
144        dr->bRequest = request;
145        dr->wValue = cpu_to_le16(value);
146        dr->wIndex = cpu_to_le16(index);
147        dr->wLength = cpu_to_le16(size);
148
149        /* dbg("usb_control_msg"); */
150
151        ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
152
153        kfree(dr);
154
155        return ret;
156}
157EXPORT_SYMBOL_GPL(usb_control_msg); 

一 般对于 struct usb_device *dev, unsigned int pipe, __u8 request,这前三个参数和void *data,__u16 size, int timeout后三个参数没有什么疑问,主要是中间几个__u8 requesttype, __u16 value, __u16 index,

requesttype 
requesttype有三部分组成,见以前日志:requesttype 。在内核中为这个三部分分别作了宏定义,分别对应这个字段的三部分:

 程序代码
linux+v2.6.35/include/linux/usb/ch9.h
/* CONTROL REQUEST SUPPORT */
  41
  42/*
  43 * USB directions
  44 *
  45 * This bit flag is used in endpoint descriptors' bEndpointAddress field.
  46 * It's also one of three fields in control requests bRequestType.
  47 */
  48#define USB_DIR_OUT                     0               /* to device */
  49#define USB_DIR_IN                      0x80            /* to host */
  50
  51/*
  52 * USB types, the second of three bRequestType fields
  53 */
  54#define USB_TYPE_MASK                   (0x03 << 5)
  55#define USB_TYPE_STANDARD               (0x00 << 5)
  56#define USB_TYPE_CLASS                  (0x01 << 5)
  57#define USB_TYPE_VENDOR                 (0x02 << 5)
  58#define USB_TYPE_RESERVED               (0x03 << 5)
  59
  60/*
  61 * USB recipients, the third of three bRequestType fields
  62 */
  63#define USB_RECIP_MASK                  0x1f
  64#define USB_RECIP_DEVICE                0x00
  65#define USB_RECIP_INTERFACE             0x01
  66#define USB_RECIP_ENDPOINT              0x02
  67#define USB_RECIP_OTHER                 0x03
  68/* From Wireless USB 1.0 */
  69#define USB_RECIP_PORT                  0x04
  70#define USB_RECIP_RPIPE         0x05 

value :2个字节,高字节是报告类型(1为输入,2为输出,3为特性);低字节为报告ID(预设为0)。例如:
wValue.LowByte   00h        Report ID 
wValue.HiByte      03h         Feature Report

index :索引字段是2个字节,描述的是接口号

usb_control_msg函数用法和说明的更多相关文章

  1. kmalloc/kfree,vmalloc/vfree函数用法和区别

    http://blog.csdn.net/tigerjibo/article/details/6412881 kmalloc/kfree,vmalloc/vfree函数用法和区别 1.kmalloc ...

  2. android studio没有浮现函数用法和属性说明?

    最近转用android studio,在使用eclipse和android studio时原本在鼠标停留处或智能提示能浮现文档相关内容,但我的是一直显示Fetching Documentation…… ...

  3. Python:匿名函数lambda的函数用法和排序用法

    一.介绍: Lambda函数,是一个匿名函数,创建语法: lambda parameters:express parameters:可选,如果提供,通常是逗号分隔的变量表达式形式,即位置参数. exp ...

  4. Signal ()函数用法和总结

    void(* signal(int sig,void(* func)(int)))(int); 设置处理信号的功能 指定使用sig指定的信号编号处理信号的方法. 参数func指定程序可以处理信号的三种 ...

  5. python内置函数sorted()及sort() 函数用法和区别

    python内置函数sorted(),sort()都有排序的意思,但是两者有本质的区别,sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作,list 的 sort ...

  6. Python 匿名函数用法和return语句

    匿名函数用法1.什么是匿名函数    函数定义过程中,没有给定名称函数,python中用lambda表达式创建匿名函数    lambda只是一个表达式,函数体比def简单    lambda主题是一 ...

  7. Python find函数用法和概念

    概念: Python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返 ...

  8. 《APUE》中的函数整理

    第1章 unix基础知识 1. char *strerror(int errnum) 该函数将errnum(就是errno值)映射为一个出错信息字符串,返回该字符串指针.声明在string.h文件中. ...

  9. SQLServer之修改标量值函数

    修改标量值函数注意事项 更改先前通过执行 CREATE FUNCTION 语句创建的现有 Transact-SQL 或 CLR 函数,但不更改权限,也不影响任何相关的函数.存储过程或触发器. 不能用 ...

随机推荐

  1. time since epoch

    C++11 提供了新的获取系统时间的库函数,在获取时间的时候一般常用的是获取time since epoch,下面来看一下如何获取这个时间. #include <iostream> #in ...

  2. Docker的入门使用(初探总结)

    Docker容器包含两种(Linux,Windows)内核,常用的为Linux. linux ,mac,windows8及以下(boot2docker,通过Linux虚拟机实现)的Docker提供Li ...

  3. linux下&、nohup与screen的比较

    & 首先,linux进程是区分前台进程和后台进程的. 通常,在终端输入的命令执行的前台进程模式.如果一个命令要执行好久,就会阻塞住终端好久,不能进行其他工作,所以,我们可以把执行花费时间很长的 ...

  4. 页面用一个遮罩层显示加载,加载完后隐藏该div

    <div id="background" class="background" style="display: none; "> ...

  5. gson 说明

    JSON对象格式 法兹测试仪测试案例编纂JavaScript对象表示法(JSON)格式的特殊字符转义,类型等,由于谷歌GSON是底层的JSON库处理类型的详细说明,请参阅到GSON文档的详细信息,请参 ...

  6. BZOJ4628 BJOI2016IP地址(trie)

    离线,每次修改相当于对该规则的所有匹配点的值+1,考虑在trie上打加法标记和匹配标记,匹配标记不下传,加法标记下传遇到匹配标记时清空.注意是用b时刻前缀-a时刻前缀,而不是(a-1)时刻前缀,具体我 ...

  7. Reachability from the Capital CodeForces - 999E(强连通分量 缩点 入度为0的点)

    题意: 问至少加几条边 能使点s可以到达所有的点 解析: 无向图的连通分量意义就是  在这个连通分量里 没两个点之间至少有一条可以相互到达的路径 所以 我们符合这种关系的点放在一起, 由s向这些点的任 ...

  8. The writing on the wall 南京网络赛2018B题

    样例输入复制 2 3 3 0 3 3 1 2 2 样例输出复制 Case #1: 36 Case #2: 20 题目来源 ACM-ICPC 2018 南京赛区网络预赛 题意: 就是求图中去掉涂黑的方格 ...

  9. Continuation-passing style

    Continuation-passing style 参考书籍: EOPL (  Essentials of Programming Languages, 3rd Edition ) 作者:知乎用户链 ...

  10. APIO模拟赛(HGOI20180909)

    想法:贪心. A.最大高度大的先剪 首先需要知道: 1.每个草最多剪1次 假设有个草剪了2次,显然可以放到最后一次剪得效果和剪2次的效果一样的, 为了少剪那么草最多剪去一次,从而,步数step> ...