Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: pkt-func.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)pkt-func.fth 1.1 07/01/24 | |
43 | purpose: USB Data Packet Manipulation | |
44 | \ See license at end of file | |
45 | ||
46 | hex | |
47 | headers | |
48 | ||
49 | \ XXX This code assumes the device and configuration descriptors are ok. | |
50 | ||
51 | false value class-in-dev? | |
52 | ||
53 | : find-desc ( adr type -- adr' ) | |
54 | swap begin ?dup while ( type adr ) | |
55 | dup 1+ c@ 2 pick = if 0 else dup c@ + then | |
56 | ( type adr' ) | |
57 | repeat nip ( adr ) | |
58 | ; | |
59 | ||
60 | : find-intf-desc ( adr intfidx -- adr ) | |
61 | swap begin ( intfidx adr ) | |
62 | INTERFACE find-desc ( intfidx adr' ) | |
63 | swap ?dup while ( adr intfidx ) | |
64 | 1- swap ( intfidx' adr ) | |
65 | dup c@ + ( intfidx adr' ) | |
66 | repeat | |
67 | ; | |
68 | ||
69 | : get-class ( dev-adr cfg-adr intfidx -- protocol subclass class ) | |
70 | rot dup 4 + c@ ?dup 0= if ( cfg-adr intfidx dev-adr ) | |
71 | false to class-in-dev? \ Class is not in device descriptor | |
72 | drop find-intf-desc ( intf-adr ) | |
73 | dup 5 + c@ swap dup 6 + c@ swap 7 + c@ | |
74 | else \ Class is in device-descriptor | |
75 | true to class-in-dev? ( cfg-adr intfidx dev-adr class ) | |
76 | 2swap 2drop ( dev-adr class ) | |
77 | swap dup 5 + c@ swap 6 + c@ | |
78 | then | |
79 | ; | |
80 | ||
81 | : get-vid ( adr -- vendor product rev ) | |
82 | dup 8 + le-w@ swap dup d# 10 + le-w@ swap c + le-w@ | |
83 | ; | |
84 | ||
85 | : unicode$>ascii$ ( adr -- actual ) | |
86 | dup c@ 2 - 2/ swap 2 + over 0 ?do ( actual adr' ) | |
87 | dup i 2* 1+ + c@ 0= if \ ASCII | |
88 | dup i 2* + c@ ( actual adr c ) | |
89 | else \ Non-ascii | |
90 | ascii ? ( actual adr c ) | |
91 | then | |
92 | over 2 - i + c! ( actual adr ) | |
93 | loop drop | |
94 | ; | |
95 | ||
96 | \ XXX In the future, maybe we can decode more languages. | |
97 | : encoded$>ascii$ ( adr lang -- actual ) | |
98 | drop unicode$>ascii$ | |
99 | ; | |
100 | ||
101 | headers | |
102 | ||
103 | \ LICENSE_BEGIN | |
104 | \ Copyright (c) 2006 FirmWorks | |
105 | \ | |
106 | \ Permission is hereby granted, free of charge, to any person obtaining | |
107 | \ a copy of this software and associated documentation files (the | |
108 | \ "Software"), to deal in the Software without restriction, including | |
109 | \ without limitation the rights to use, copy, modify, merge, publish, | |
110 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
111 | \ permit persons to whom the Software is furnished to do so, subject to | |
112 | \ the following conditions: | |
113 | \ | |
114 | \ The above copyright notice and this permission notice shall be | |
115 | \ included in all copies or substantial portions of the Software. | |
116 | \ | |
117 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
118 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
119 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
120 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
121 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
122 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
123 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
124 | \ | |
125 | \ LICENSE_END |