aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/tnetstring.py
blob: 58519675482ac45960b726c4fe4e51db2ca4ef1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# imported from the tnetstring project: https://github.com/rfk/tnetstring
#
# Copyright (c) 2011 Ryan Kelly
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
tnetstring:  data serialization using typed netstrings
======================================================


This is a data serialization library. It's a lot like JSON but it uses a
new syntax called "typed netstrings" that Zed has proposed for use in the
Mongrel2 webserver.  It's designed to be simpler and easier to implement
than JSON, with a happy consequence of also being faster in many cases.

An ordinary netstring is a blob of data prefixed with its length and postfixed
with a sanity-checking comma.  The string "hello world" encodes like this::

    11:hello world,

Typed netstrings add other datatypes by replacing the comma with a type tag.
Here's the integer 12345 encoded as a tnetstring::

    5:12345#

And here's the list [12345,True,0] which mixes integers and bools::

    19:5:12345#4:true!1:0#]

Simple enough?  This module gives you the following functions:

    :dump:    dump an object as a tnetstring to a file
    :dumps:   dump an object as a tnetstring to a string
    :load:    load a tnetstring-encoded object from a file
    :loads:   load a tnetstring-encoded object from a string
    :pop:     pop a tnetstring-encoded object from the front of a string

Note that since parsing a tnetstring requires reading all the data into memory
at once, there's no efficiency gain from using the file-based versions of these
functions.  They're only here so you can use load() to read precisely one
item from a file or socket without consuming any extra data.

By default tnetstrings work only with byte strings, not unicode.  If you want
unicode strings then pass an optional encoding to the various functions,
like so::

    >>> print repr(tnetstring.loads("2:\\xce\\xb1,"))
    '\\xce\\xb1'
    >>>
    >>> print repr(tnetstring.loads("2:\\xce\\xb1,","utf8"))
    u'\u03b1'

"""

__ver_major__ = 0
__ver_minor__ = 2
__ver_patch__ = 0
__ver_sub__ = ""
__version__ = "%d.%d.%d%s" % (__ver_major__,__ver_minor__,__ver_patch__,__ver_sub__)


from collections import deque


def dumps(value,encoding=None):
    """dumps(object,encoding=None) -> string

    This function dumps a python object as a tnetstring.
    """
    #  This uses a deque to collect output fragments in reverse order,
    #  then joins them together at the end.  It's measurably faster
    #  than creating all the intermediate strings.
    #  If you're reading this to get a handle on the tnetstring format,
    #  consider the _gdumps() function instead; it's a standard top-down
    #  generator that's simpler to understand but much less efficient.
    q = deque()
    _rdumpq(q,0,value,encoding)
    return "".join(q)


def dump(value,file,encoding=None):
    """dump(object,file,encoding=None)

    This function dumps a python object as a tnetstring and writes it to
    the given file.
    """
    file.write(dumps(value,encoding))
    file.flush()


def _rdumpq(q,size,value,encoding=None):
    """Dump value as a tnetstring, to a deque instance, last chunks first.

    This function generates the tnetstring representation of the given value,
    pushing chunks of the output onto the given deque instance.  It pushes
    the last chunk first, then recursively generates more chunks.

    When passed in the current size of the string in the queue, it will return
    the new size of the string in the queue.

    Operating last-chunk-first makes it easy to calculate the size written
    for recursive structures without having to build their representation as
    a string.  This is measurably faster than generating the intermediate
    strings, especially on deeply nested structures.
    """
    write = q.appendleft
    if value is None:
        write("0:~")
        return size + 3
    if value is True:
        write("4:true!")
        return size + 7
    if value is False:
        write("5:false!")
        return size + 8
    if isinstance(value,(int,long)):
        data = str(value)
        ldata = len(data)
        span = str(ldata)
        write("#")
        write(data)
        write(":")
        write(span)
        return size + 2 + len(span) + ldata
    if isinstance(value,(float,)):
        #  Use repr() for float rather than str().
        #  It round-trips more accurately.
        #  Probably unnecessary in later python versions that
        #  use David Gay's ftoa routines.
        data = repr(value)
        ldata = len(data)
        span = str(ldata)
        write("^")
        write(data)
        write(":")
        write(span)
        return size + 2 + len(span) + ldata
    if isinstance(value,str):
        lvalue = len(value)
        span = str(lvalue)
        write(",")
        write(value)
        write(":")
        write(span)
        return size + 2 + len(span) + lvalue
    if isinstance(value,(list,tuple,)):
        write("]")
        init_size = size = size + 1
        for item in reversed(value):
            size = _rdumpq(q,size,item,encoding)
        span = str(size - init_size)
        write(":")
        write(span)
        return size + 1 + len(span)
    if isinstance(value,dict):
        write("}")
        init_size = size = size + 1
        for (k,v) in value.iteritems():
            size = _rdumpq(q,size,v,encoding)
            size = _rdumpq(q,size,k,encoding)
        span = str(size - init_size)
        write(":")
        write(span)
        return size + 1 + len(span)
    if isinstance(value,unicode):
        if encoding is None:
            raise ValueError("must specify encoding to dump unicode strings")
        value = value.encode(encoding)
        lvalue = len(value)
        span = str(lvalue)
        write(",")
        write(value)
        write(":")
        write(span)
        return size + 2 + len(span) + lvalue
    raise ValueError("unserializable object")


def _gdumps(value,encoding):
    """Generate fragments of value dumped as a tnetstring.

    This is the naive dumping algorithm, implemented as a generator so that
    it's easy to pass to "".join() without building a new list.

    This is mainly here for comparison purposes; the _rdumpq version is
    measurably faster as it doesn't have to build intermediate strins.
    """
    if value is None:
        yield "0:~"
    elif value is True:
        yield "4:true!"
    elif value is False:
        yield "5:false!"
    elif isinstance(value,(int,long)):
        data = str(value)
        yield str(len(data))
        yield ":"
        yield data
        yield "#"
    elif isinstance(value,(float,)):
        data = repr(value)
        yield str(len(data))
        yield ":"
        yield data
        yield "^"
    elif isinstance(value,(str,)):
        yield str(len(value))
        yield ":"
        yield value
        yield ","
    elif isinstance(value,(list,tuple,)):
        sub = []
        for item in value:
            sub.extend(_gdumps(item))
        sub = "".join(sub)
        yield str(len(sub))
        yield ":"
        yield sub
        yield "]"
    elif isinstance(value,(dict,)):
        sub = []
        for (k,v) in value.iteritems():
            sub.extend(_gdumps(k))
            sub.extend(_gdumps(v))
        sub = "".join(sub)
        yield str(len(sub))
        yield ":"
        yield sub
        yield "}"
    elif isinstance(value,(unicode,)):
        if encoding is None:
            raise ValueError("must specify encoding to dump unicode strings")
        value = value.encode(encoding)
        yield str(len(value))
        yield ":"
        yield value
        yield ","
    else:
        raise ValueError("unserializable object")


def loads(string,encoding=None):
    """loads(string,encoding=None) -> object

    This function parses a tnetstring into a python object.
    """
    #  No point duplicating effort here.  In the C-extension version,
    #  loads() is measurably faster then pop() since it can avoid
    #  the overhead of building a second string.
    return pop(string,encoding)[0]


def load(file,encoding=None):
    """load(file,encoding=None) -> object

    This function reads a tnetstring from a file and parses it into a
    python object.  The file must support the read() method, and this
    function promises not to read more data than necessary.
    """
    #  Read the length prefix one char at a time.
    #  Note that the netstring spec explicitly forbids padding zeros.
    c = file.read(1)
    if not c.isdigit():
        raise ValueError("not a tnetstring: missing or invalid length prefix")
    datalen = ord(c) - ord("0")
    c = file.read(1)
    if datalen != 0:
        while c.isdigit():
            datalen = (10 * datalen) + (ord(c) - ord("0"))
            if datalen > 999999999:
                errmsg = "not a tnetstring: absurdly large length prefix"
                raise ValueError(errmsg)
            c = file.read(1)
    if c != ":":
        raise ValueError("not a tnetstring: missing or invalid length prefix")
    #  Now we can read and parse the payload.
    #  This repeats the dispatch logic of pop() so we can avoid
    #  re-constructing the outermost tnetstring.
    data = file.read(datalen)
    if len(data) != datalen:
        raise ValueError("not a tnetstring: length prefix too big")
    type = file.read(1)
    if type == ",":
        if encoding is not None:
            return data.decode(encoding)
        return data
    if type == "#":
        try:
            return int(data)
        except ValueError:
            raise ValueError("not a tnetstring: invalid integer literal")
    if type == "^":
        try:
            return float(data)
        except ValueError:
            raise ValueError("not a tnetstring: invalid float literal")
    if type == "!":
        if data == "true":
            return True
        elif data == "false":
            return False
        else:
            raise ValueError("not a tnetstring: invalid boolean literal")
    if type == "~":
        if data:
            raise ValueError("not a tnetstring: invalid null literal")
        return None
    if type == "]":
        l = []
        while data:
            (item,data) = pop(data,encoding)
            l.append(item)
        return l
    if type == "}":
        d = {}
        while data:
            (key,data) = pop(data,encoding)
            (val,data) = pop(data,encoding)
            d[key] = val
        return d
    raise ValueError("unknown type tag")



def pop(string,encoding=None):
    """pop(string,encoding=None) -> (object, remain)

    This function parses a tnetstring into a python object.
    It returns a tuple giving the parsed object and a string
    containing any unparsed data from the end of the string.
    """
    #  Parse out data length, type and remaining string.
    try:
        (dlen,rest) = string.split(":",1)
        dlen = int(dlen)
    except ValueError:
        raise ValueError("not a tnetstring: missing or invalid length prefix")
    try:
        (data,type,remain) = (rest[:dlen],rest[dlen],rest[dlen+1:])
    except IndexError:
        #  This fires if len(rest) < dlen, meaning we don't need
        #  to further validate that data is the right length.
        raise ValueError("not a tnetstring: invalid length prefix")
    #  Parse the data based on the type tag.
    if type == ",":
        if encoding is not None:
            return (data.decode(encoding),remain)
        return (data,remain)
    if type == "#":
        try:
            return (int(data),remain)
        except ValueError:
            raise ValueError("not a tnetstring: invalid integer literal")
    if type == "^":
        try:
            return (float(data),remain)
        except ValueError:
            raise ValueError("not a tnetstring: invalid float literal")
    if type == "!":
        if data == "true":
            return (True,remain)
        elif data == "false":
            return (False,remain)
        else:
            raise ValueError("not a tnetstring: invalid boolean literal")
    if type == "~":
        if data:
            raise ValueError("not a tnetstring: invalid null literal")
        return (None,remain)
    if type == "]":
        l = []
        while data:
            (item,data) = pop(data,encoding)
            l.append(item)
        return (l,remain)
    if type == "}":
        d = {}
        while data:
            (key,data) = pop(data,encoding)
            (val,data) = pop(data,encoding)
            d[key] = val
        return (d,remain)
    raise ValueError("unknown type tag")
AddDepends/usb-serial) endef define KernelPackage/usb-serial-ti-usb/description Kernel support for TI USB 3410/5052 devices endef $(eval $(call KernelPackage,usb-serial-ti-usb)) define KernelPackage/usb-serial-ipw TITLE:=Support for IPWireless 3G devices KCONFIG:=CONFIG_USB_SERIAL_IPW FILES:=$(LINUX_DIR)/drivers/usb/serial/ipw.ko AUTOLOAD:=$(call AutoProbe,ipw) $(call AddDepends/usb-serial,+kmod-usb-serial-wwan) endef $(eval $(call KernelPackage,usb-serial-ipw)) define KernelPackage/usb-serial-mct TITLE:=Support for Magic Control Tech. devices KCONFIG:=CONFIG_USB_SERIAL_MCT_U232 FILES:=$(LINUX_DIR)/drivers/usb/serial/mct_u232.ko AUTOLOAD:=$(call AutoProbe,mct_u232) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-mct/description Kernel support for Magic Control Technology USB-to-Serial converters endef $(eval $(call KernelPackage,usb-serial-mct)) define KernelPackage/usb-serial-mos7720 TITLE:=Support for Moschip MOS7720 devices KCONFIG:=CONFIG_USB_SERIAL_MOS7720 FILES:=$(LINUX_DIR)/drivers/usb/serial/mos7720.ko AUTOLOAD:=$(call AutoProbe,mos7720) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-mos7720/description Kernel support for Moschip MOS7720 USB-to-Serial converters endef $(eval $(call KernelPackage,usb-serial-mos7720)) define KernelPackage/usb-serial-pl2303 TITLE:=Support for Prolific PL2303 devices KCONFIG:=CONFIG_USB_SERIAL_PL2303 FILES:=$(LINUX_DIR)/drivers/usb/serial/pl2303.ko AUTOLOAD:=$(call AutoProbe,pl2303) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-pl2303/description Kernel support for Prolific PL2303 USB-to-Serial converters endef $(eval $(call KernelPackage,usb-serial-pl2303)) define KernelPackage/usb-serial-cp210x TITLE:=Support for Silicon Labs cp210x devices KCONFIG:=CONFIG_USB_SERIAL_CP210X FILES:=$(LINUX_DIR)/drivers/usb/serial/cp210x.ko AUTOLOAD:=$(call AutoProbe,cp210x) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-cp210x/description Kernel support for Silicon Labs cp210x USB-to-Serial converters endef $(eval $(call KernelPackage,usb-serial-cp210x)) define KernelPackage/usb-serial-ark3116 TITLE:=Support for ArkMicroChips ARK3116 devices KCONFIG:=CONFIG_USB_SERIAL_ARK3116 FILES:=$(LINUX_DIR)/drivers/usb/serial/ark3116.ko AUTOLOAD:=$(call AutoProbe,ark3116) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-ark3116/description Kernel support for ArkMicroChips ARK3116 USB-to-Serial converters endef $(eval $(call KernelPackage,usb-serial-ark3116)) define KernelPackage/usb-serial-oti6858 TITLE:=Support for Ours Technology OTI6858 devices KCONFIG:=CONFIG_USB_SERIAL_OTI6858 FILES:=$(LINUX_DIR)/drivers/usb/serial/oti6858.ko AUTOLOAD:=$(call AutoProbe,oti6858) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-oti6858/description Kernel support for Ours Technology OTI6858 USB-to-Serial converters endef $(eval $(call KernelPackage,usb-serial-oti6858)) define KernelPackage/usb-serial-sierrawireless TITLE:=Support for Sierra Wireless devices KCONFIG:=CONFIG_USB_SERIAL_SIERRAWIRELESS FILES:=$(LINUX_DIR)/drivers/usb/serial/sierra.ko AUTOLOAD:=$(call AutoProbe,sierra) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-sierrawireless/description Kernel support for Sierra Wireless devices endef $(eval $(call KernelPackage,usb-serial-sierrawireless)) define KernelPackage/usb-serial-motorola-phone TITLE:=Support for Motorola usb phone KCONFIG:=CONFIG_USB_SERIAL_MOTOROLA FILES:=$(LINUX_DIR)/drivers/usb/serial/moto_modem.ko AUTOLOAD:=$(call AutoProbe,moto_modem) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-motorola-phone/description Kernel support for Motorola usb phone endef $(eval $(call KernelPackage,usb-serial-motorola-phone)) define KernelPackage/usb-serial-visor TITLE:=Support for Handspring Visor devices KCONFIG:=CONFIG_USB_SERIAL_VISOR FILES:=$(LINUX_DIR)/drivers/usb/serial/visor.ko AUTOLOAD:=$(call AutoProbe,visor) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-visor/description Kernel support for Handspring Visor PDAs endef $(eval $(call KernelPackage,usb-serial-visor)) define KernelPackage/usb-serial-cypress-m8 TITLE:=Support for CypressM8 USB-Serial KCONFIG:=CONFIG_USB_SERIAL_CYPRESS_M8 FILES:=$(LINUX_DIR)/drivers/usb/serial/cypress_m8.ko AUTOLOAD:=$(call AutoProbe,cypress_m8) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-cypress-m8/description Kernel support for devices with Cypress M8 USB to Serial chip (for example, the Delorme Earthmate LT-20 GPS) Supported microcontrollers in the CY4601 family are: CY7C63741 CY7C63742 CY7C63743 CY7C64013 endef $(eval $(call KernelPackage,usb-serial-cypress-m8)) define KernelPackage/usb-serial-keyspan TITLE:=Support for Keyspan USB-to-Serial devices KCONFIG:= \ CONFIG_USB_SERIAL_KEYSPAN \ CONFIG_USB_SERIAL_KEYSPAN_USA28 \ CONFIG_USB_SERIAL_KEYSPAN_USA28X \ CONFIG_USB_SERIAL_KEYSPAN_USA28XA \ CONFIG_USB_SERIAL_KEYSPAN_USA28XB \ CONFIG_USB_SERIAL_KEYSPAN_USA19 \ CONFIG_USB_SERIAL_KEYSPAN_USA18X \ CONFIG_USB_SERIAL_KEYSPAN_USA19W \ CONFIG_USB_SERIAL_KEYSPAN_USA19QW \ CONFIG_USB_SERIAL_KEYSPAN_USA19QI \ CONFIG_USB_SERIAL_KEYSPAN_MPR \ CONFIG_USB_SERIAL_KEYSPAN_USA49W \ CONFIG_USB_SERIAL_KEYSPAN_USA49WLC FILES:= \ $(LINUX_DIR)/drivers/usb/serial/keyspan.ko \ $(wildcard $(LINUX_DIR)/drivers/usb/misc/ezusb.ko) AUTOLOAD:=$(call AutoProbe,ezusb keyspan) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-keyspan/description Kernel support for Keyspan USB-to-Serial devices endef $(eval $(call KernelPackage,usb-serial-keyspan)) define KernelPackage/usb-serial-wwan TITLE:=Support for GSM and CDMA modems KCONFIG:=CONFIG_USB_SERIAL_WWAN FILES:=$(LINUX_DIR)/drivers/usb/serial/usb_wwan.ko AUTOLOAD:=$(call AutoProbe,usb_wwan) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-wwan/description Kernel support for USB GSM and CDMA modems endef $(eval $(call KernelPackage,usb-serial-wwan)) define KernelPackage/usb-serial-option TITLE:=Support for Option HSDPA modems DEPENDS:=+kmod-usb-serial-wwan KCONFIG:=CONFIG_USB_SERIAL_OPTION FILES:=$(LINUX_DIR)/drivers/usb/serial/option.ko AUTOLOAD:=$(call AutoProbe,option) $(call AddDepends/usb-serial) endef define KernelPackage/usb-serial-option/description Kernel support for Option HSDPA modems endef $(eval $(call KernelPackage,usb-serial-option)) define KernelPackage/usb-serial-qualcomm TITLE:=Support for Qualcomm USB serial KCONFIG:=CONFIG_USB_SERIAL_QUALCOMM FILES:=$(LINUX_DIR)/drivers/usb/serial/qcserial.ko AUTOLOAD:=$(call AutoProbe,qcserial) $(call AddDepends/usb-serial,+kmod-usb-serial-wwan) endef define KernelPackage/usb-serial-qualcomm/description Kernel support for Qualcomm USB Serial devices (Gobi) endef $(eval $(call KernelPackage,usb-serial-qualcomm)) define KernelPackage/usb-storage TITLE:=USB Storage support DEPENDS:= +kmod-scsi-core KCONFIG:=CONFIG_USB_STORAGE FILES:=$(LINUX_DIR)/drivers/usb/storage/usb-storage.ko AUTOLOAD:=$(call AutoProbe,usb-storage,1) $(call AddDepends/usb) endef define KernelPackage/usb-storage/description Kernel support for USB Mass Storage devices endef $(eval $(call KernelPackage,usb-storage)) define KernelPackage/usb-storage-extras SUBMENU:=$(USB_MENU) TITLE:=Extra drivers for usb-storage DEPENDS:=+kmod-usb-storage KCONFIG:= \ CONFIG_USB_STORAGE_ALAUDA \ CONFIG_USB_STORAGE_CYPRESS_ATACB \ CONFIG_USB_STORAGE_DATAFAB \ CONFIG_USB_STORAGE_FREECOM \ CONFIG_USB_STORAGE_ISD200 \ CONFIG_USB_STORAGE_JUMPSHOT \ CONFIG_USB_STORAGE_KARMA \ CONFIG_USB_STORAGE_SDDR09 \ CONFIG_USB_STORAGE_SDDR55 \ CONFIG_USB_STORAGE_USBAT FILES:= \ $(LINUX_DIR)/drivers/usb/storage/ums-alauda.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-cypress.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-datafab.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-freecom.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-isd200.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-jumpshot.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-karma.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-sddr09.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-sddr55.ko \ $(LINUX_DIR)/drivers/usb/storage/ums-usbat.ko AUTOLOAD:=$(call AutoProbe,ums-alauda ums-cypress ums-datafab \ ums-freecom ums-isd200 ums-jumpshot \ ums-karma ums-sddr09 ums-sddr55 ums-usbat) endef define KernelPackage/usb-storage-extras/description Say Y here if you want to have some more drivers, such as for SmartMedia card readers endef $(eval $(call KernelPackage,usb-storage-extras)) define KernelPackage/usb-atm TITLE:=Support for ATM on USB bus DEPENDS:=+kmod-atm KCONFIG:=CONFIG_USB_ATM FILES:=$(LINUX_DIR)/drivers/usb/atm/usbatm.ko AUTOLOAD:=$(call AutoProbe,usbatm) $(call AddDepends/usb) endef define KernelPackage/usb-atm/description Kernel support for USB DSL modems endef $(eval $(call KernelPackage,usb-atm)) define AddDepends/usb-atm SUBMENU:=$(USB_MENU) DEPENDS+=kmod-usb-atm $(1) endef define KernelPackage/usb-atm-speedtouch TITLE:=SpeedTouch USB ADSL modems support KCONFIG:=CONFIG_USB_SPEEDTOUCH FILES:=$(LINUX_DIR)/drivers/usb/atm/speedtch.ko AUTOLOAD:=$(call AutoProbe,speedtch) $(call AddDepends/usb-atm) endef define KernelPackage/usb-atm-speedtouch/description Kernel support for SpeedTouch USB ADSL modems endef $(eval $(call KernelPackage,usb-atm-speedtouch)) define KernelPackage/usb-atm-ueagle TITLE:=Eagle 8051 based USB ADSL modems support FILES:=$(LINUX_DIR)/drivers/usb/atm/ueagle-atm.ko KCONFIG:=CONFIG_USB_UEAGLEATM AUTOLOAD:=$(call AutoProbe,ueagle-atm) $(call AddDepends/usb-atm) endef define KernelPackage/usb-atm-ueagle/description Kernel support for Eagle 8051 based USB ADSL modems endef $(eval $(call KernelPackage,usb-atm-ueagle)) define KernelPackage/usb-atm-cxacru TITLE:=cxacru FILES:=$(LINUX_DIR)/drivers/usb/atm/cxacru.ko KCONFIG:=CONFIG_USB_CXACRU AUTOLOAD:=$(call AutoProbe,cxacru) $(call AddDepends/usb-atm) endef define KernelPackage/usb-atm-cxacru/description Kernel support for cxacru based USB ADSL modems endef $(eval $(call KernelPackage,usb-atm-cxacru)) define KernelPackage/usb-net TITLE:=Kernel modules for USB-to-Ethernet convertors KCONFIG:=CONFIG_USB_USBNET CONFIG_MII=y AUTOLOAD:=$(call AutoProbe,usbnet) ifeq ($(strip $(call CompareKernelPatchVer,$(KERNEL_PATCHVER),lt,3.12.0)),1) FILES:=$(LINUX_DIR)/drivers/$(USBNET_DIR)/usbnet.ko else FILES:=\ $(LINUX_DIR)/drivers/$(USBNET_DIR)/usbnet.ko \ $(LINUX_DIR)/drivers/net/mii.ko endif $(call AddDepends/usb) endef define KernelPackage/usb-net/description Kernel modules for USB-to-Ethernet convertors endef $(eval $(call KernelPackage,usb-net)) define AddDepends/usb-net SUBMENU:=$(USB_MENU) DEPENDS+=kmod-usb-net $(1) endef define KernelPackage/usb-net-asix TITLE:=Kernel module for USB-to-Ethernet Asix convertors DEPENDS:=+!LINUX_3_3:kmod-libphy KCONFIG:=CONFIG_USB_NET_AX8817X FILES:=$(LINUX_DIR)/drivers/$(USBNET_DIR)/asix.ko AUTOLOAD:=$(call AutoProbe,asix) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-asix/description Kernel module for USB-to-Ethernet Asix convertors endef $(eval $(call KernelPackage,usb-net-asix)) define KernelPackage/usb-net-hso TITLE:=Kernel module for Option USB High Speed Mobile Devices KCONFIG:=CONFIG_USB_HSO FILES:= \ $(LINUX_DIR)/drivers/$(USBNET_DIR)/hso.ko AUTOLOAD:=$(call AutoProbe,hso) $(call AddDepends/usb-net) $(call AddDepends/rfkill) endef define KernelPackage/usb-net-hso/description Kernel module for Option USB High Speed Mobile Devices endef $(eval $(call KernelPackage,usb-net-hso)) define KernelPackage/usb-net-kaweth TITLE:=Kernel module for USB-to-Ethernet Kaweth convertors KCONFIG:=CONFIG_USB_KAWETH FILES:=$(LINUX_DIR)/drivers/$(USBNET_DIR)/kaweth.ko AUTOLOAD:=$(call AutoProbe,kaweth) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-kaweth/description Kernel module for USB-to-Ethernet Kaweth convertors endef $(eval $(call KernelPackage,usb-net-kaweth)) define KernelPackage/usb-net-pegasus TITLE:=Kernel module for USB-to-Ethernet Pegasus convertors KCONFIG:=CONFIG_USB_PEGASUS FILES:=$(LINUX_DIR)/drivers/$(USBNET_DIR)/pegasus.ko AUTOLOAD:=$(call AutoProbe,pegasus) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-pegasus/description Kernel module for USB-to-Ethernet Pegasus convertors endef $(eval $(call KernelPackage,usb-net-pegasus)) define KernelPackage/usb-net-mcs7830 TITLE:=Kernel module for USB-to-Ethernet MCS7830 convertors KCONFIG:=CONFIG_USB_NET_MCS7830 FILES:=$(LINUX_DIR)/drivers/$(USBNET_DIR)/mcs7830.ko AUTOLOAD:=$(call AutoProbe,mcs7830) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-mcs7830/description Kernel module for USB-to-Ethernet MCS7830 convertors endef $(eval $(call KernelPackage,usb-net-mcs7830)) define KernelPackage/usb-net-dm9601-ether TITLE:=Support for DM9601 ethernet connections KCONFIG:=CONFIG_USB_NET_DM9601 FILES:=$(LINUX_DIR)/drivers/$(USBNET_DIR)/dm9601.ko AUTOLOAD:=$(call AutoProbe,dm9601) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-dm9601-ether/description Kernel support for USB DM9601 devices endef $(eval $(call KernelPackage,usb-net-dm9601-ether)) define KernelPackage/usb-net-cdc-ether TITLE:=Support for cdc ethernet connections KCONFIG:=CONFIG_USB_NET_CDCETHER FILES:=$(LINUX_DIR)/drivers/$(USBNET_DIR)/cdc_ether.ko AUTOLOAD:=$(call AutoProbe,cdc_ether) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-cdc-ether/description Kernel support for USB CDC Ethernet devices endef $(eval $(call KernelPackage,usb-net-cdc-ether)) define KernelPackage/usb-net-qmi-wwan TITLE:=QMI WWAN driver KCONFIG:=CONFIG_USB_NET_QMI_WWAN FILES:= $(LINUX_DIR)/drivers/$(USBNET_DIR)/qmi_wwan.ko AUTOLOAD:=$(call AutoProbe,qmi_wwan) $(call AddDepends/usb-net,+kmod-usb-wdm) endef define KernelPackage/usb-net-qmi-wwan/description QMI WWAN driver for Qualcomm MSM based 3G and LTE modems endef $(eval $(call KernelPackage,usb-net-qmi-wwan)) define KernelPackage/usb-net-rndis TITLE:=Support for RNDIS connections KCONFIG:=CONFIG_USB_NET_RNDIS_HOST FILES:= $(LINUX_DIR)/drivers/$(USBNET_DIR)/rndis_host.ko AUTOLOAD:=$(call AutoProbe,rndis_host) $(call AddDepends/usb-net,+kmod-usb-net-cdc-ether) endef define KernelPackage/usb-net-rndis/description Kernel support for RNDIS connections endef $(eval $(call KernelPackage,usb-net-rndis)) define KernelPackage/usb-net-cdc-mbim SUBMENU:=$(USB_MENU) TITLE:=Kernel module for MBIM Devices KCONFIG:=CONFIG_USB_NET_CDC_MBIM FILES:= \ $(LINUX_DIR)/drivers/$(USBNET_DIR)/cdc_mbim.ko AUTOLOAD:=$(call AutoProbe,cdc_mbim) $(call AddDepends/usb-net,+kmod-usb-wdm +kmod-usb-net-cdc-ncm) endef define KernelPackage/usb-net-cdc-mbim/description Kernel module for Option USB High Speed Mobile Devices endef $(eval $(call KernelPackage,usb-net-cdc-mbim)) define KernelPackage/usb-net-cdc-ncm TITLE:=Support for CDC NCM connections KCONFIG:=CONFIG_USB_NET_CDC_NCM FILES:= $(LINUX_DIR)/drivers/$(USBNET_DIR)/cdc_ncm.ko AUTOLOAD:=$(call AutoProbe,cdc_ncm) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-cdc-ncm/description Kernel support for CDC NCM connections endef $(eval $(call KernelPackage,usb-net-cdc-ncm)) define KernelPackage/usb-net-sierrawireless TITLE:=Support for Sierra Wireless devices KCONFIG:=CONFIG_USB_SIERRA_NET FILES:=$(LINUX_DIR)/drivers/net/usb/sierra_net.ko AUTOLOAD:=$(call AutoProbe,sierra_net) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-sierrawireless/description Kernel support for Sierra Wireless devices endef $(eval $(call KernelPackage,usb-net-sierrawireless)) define KernelPackage/usb-net-ipheth TITLE:=Apple iPhone USB Ethernet driver KCONFIG:=CONFIG_USB_IPHETH FILES:=$(LINUX_DIR)/drivers/net/usb/ipheth.ko AUTOLOAD:=$(call AutoProbe,ipheth) $(call AddDepends/usb-net) endef define KernelPackage/usb-net-ipheth/description Kernel support for Apple iPhone USB Ethernet driver endef $(eval $(call KernelPackage,usb-net-ipheth)) define KernelPackage/usb-hid TITLE:=Support for USB Human Input Devices KCONFIG:=CONFIG_HID_SUPPORT=y CONFIG_USB_HID CONFIG_USB_HIDDEV=y FILES:=$(LINUX_DIR)/drivers/$(USBHID_DIR)/usbhid.ko AUTOLOAD:=$(call AutoProbe,usbhid) $(call AddDepends/usb) $(call AddDepends/hid) $(call AddDepends/input,+kmod-input-evdev) endef define KernelPackage/usb-hid/description Kernel support for USB HID devices such as keyboards and mice endef $(eval $(call KernelPackage,usb-hid)) define KernelPackage/usb-yealink TITLE:=USB Yealink VOIP phone KCONFIG:=CONFIG_USB_YEALINK CONFIG_INPUT_YEALINK CONFIG_INPUT=m CONFIG_INPUT_MISC=y FILES:=$(LINUX_DIR)/drivers/$(USBINPUT_DIR)/yealink.ko AUTOLOAD:=$(call AutoProbe,yealink) $(call AddDepends/usb) $(call AddDepends/input,+kmod-input-evdev) endef define KernelPackage/usb-yealink/description Kernel support for Yealink VOIP phone endef $(eval $(call KernelPackage,usb-yealink)) define KernelPackage/usb-cm109 TITLE:=Support for CM109 device KCONFIG:=CONFIG_USB_CM109 CONFIG_INPUT_CM109 CONFIG_INPUT=m CONFIG_INPUT_MISC=y FILES:=$(LINUX_DIR)/drivers/$(USBINPUT_DIR)/cm109.ko AUTOLOAD:=$(call AutoProbe,cm109) $(call AddDepends/usb) $(call AddDepends/input,+kmod-input-evdev) endef define KernelPackage/usb-cm109/description Kernel support for CM109 VOIP phone endef $(eval $(call KernelPackage,usb-cm109)) define KernelPackage/usb-test TITLE:=USB Testing Driver DEPENDS:=@DEVEL KCONFIG:=CONFIG_USB_TEST FILES:=$(LINUX_DIR)/drivers/usb/misc/usbtest.ko $(call AddDepends/usb) endef define KernelPackage/usb-test/description Kernel support for testing USB Host Controller software endef $(eval $(call KernelPackage,usb-test)) define KernelPackage/usbip TITLE := USB-over-IP kernel support KCONFIG:= \ CONFIG_USBIP_CORE \ CONFIG_USBIP_DEBUG=n FILES:=$(LINUX_DIR)/drivers/staging/usbip/usbip-core.ko AUTOLOAD:=$(call AutoProbe,usbip-core) $(call AddDepends/usb) endef $(eval $(call KernelPackage,usbip)) define KernelPackage/usbip-client TITLE := USB-over-IP client driver DEPENDS := +kmod-usbip KCONFIG := CONFIG_USBIP_VHCI_HCD FILES := $(LINUX_DIR)/drivers/staging/usbip/vhci-hcd.$(LINUX_KMOD_SUFFIX) AUTOLOAD := $(call AutoProbe,vhci-hcd) $(call AddDepends/usb) endef $(eval $(call KernelPackage,usbip-client)) define KernelPackage/usbip-server $(call KernelPackage/usbip/Default) TITLE := USB-over-IP host driver DEPENDS := +kmod-usbip KCONFIG := CONFIG_USBIP_HOST FILES := $(LINUX_DIR)/drivers/staging/usbip/usbip-host.ko AUTOLOAD := $(call AutoProbe,usbip-host) $(call AddDepends/usb) endef $(eval $(call KernelPackage,usbip-server)) define KernelPackage/usb-chipidea TITLE:=Support for ChipIdea controllers DEPENDS:=+kmod-usb2 KCONFIG:=\ CONFIG_USB_CHIPIDEA \ CONFIG_USB_CHIPIDEA_HOST=y \ CONFIG_USB_CHIPIDEA_UDC=n \ CONFIG_USB_CHIPIDEA_DEBUG=y ifeq ($(strip $(call CompareKernelPatchVer,$(KERNEL_PATCHVER),lt,3.11.0)),1) FILES:=\ $(LINUX_DIR)/drivers/usb/chipidea/ci_hdrc.ko \ $(if $(CONFIG_OF_DEVICE),$(LINUX_DIR)/drivers/usb/chipidea/ci13xxx_imx.ko) \ $(if $(CONFIG_OF_DEVICE),$(LINUX_DIR)/drivers/usb/chipidea/usbmisc_imx$(if $(call kernel_patchver_le,3.9),6q).ko) AUTOLOAD:=$(call AutoLoad,51,ci_hdrc $(if $(CONFIG_OF_DEVICE),ci13xxx_imx usbmisc_imx$(if $(call kernel_patchver_le,3.9),6q)),1) else FILES:=\ $(LINUX_DIR)/drivers/usb/chipidea/ci_hdrc.ko \ $(if $(CONFIG_OF),$(LINUX_DIR)/drivers/usb/chipidea/ci_hdrc_imx.ko) \ $(if $(CONFIG_OF),$(LINUX_DIR)/drivers/usb/chipidea/usbmisc_imx.ko) AUTOLOAD:=$(call AutoLoad,51,ci_hdrc $(if $(CONFIG_OF),ci_hdrc_imx usbmisc_imx),1) endif $(call AddDepends/usb) endef define KernelPackage/usb-chipidea/description Kernel support for USB ChipIdea controllers endef $(eval $(call KernelPackage,usb-chipidea,1)) define KernelPackage/usb-mxs-phy TITLE:=Support for Freescale MXS USB PHY DEPENDS:=@TARGET_imx6 KCONFIG:=CONFIG_USB_MXS_PHY FILES:=\ $(LINUX_DIR)/drivers/usb/phy/phy-mxs-usb.ko AUTOLOAD:=$(call AutoLoad,52,phy-mxs-usb,1) $(call AddDepends/usb) endef define KernelPackage/usb-mxs-phy/description Kernel support for Freescale MXS USB PHY endef $(eval $(call KernelPackage,usb-mxs-phy,1)) define KernelPackage/usbmon TITLE:=USB traffic monitor KCONFIG:=CONFIG_USB_MON $(call AddDepends/usb) FILES:=$(LINUX_DIR)/drivers/usb/mon/usbmon.ko AUTOLOAD:=$(call AutoProbe,usbmon) endef define KernelPackage/usbmon/description Kernel support for USB traffic monitoring endef $(eval $(call KernelPackage,usbmon))