1<h2>device_set_filter</h2>
2<hr>
3<p>
4<strong>Function</strong> - Name an input filter for a device.
5<h3>SYNOPSIS</h3>
6<pre>
7<strong>#include&lt device/device.h&gt</strong>
8<strong>#include&lt device/net_status.h&gt</strong>
9
10<strong>kern_return_t   device_set_filter</strong>
11                <strong>(mach_port_t</strong>                             <var>device</var>,
12                 <strong>mach_port_t</strong>                       <var>receive_port</var>,
13                 <strong>mach_msg_type_name_t</strong>         <var>receive_port_type</var>,
14                 <strong>int</strong>                                   <var>priority</var>,
15                 <strong>filter_array_t</strong>                          <var>filter</var>,
16                 <strong>mach_msg_type_number_t</strong>             <var>filter_count</var><strong>);</strong>
17</pre>
18<h3>PARAMETERS</h3>
19<dl>
20<p>
21<dt> <var>device</var> 
22<dd>
23[in device send right]
24A device port
25<p>
26<dt> <var>receive_port</var> 
27<dd>
28[in filter send or receive (to be converted to send) right]
29The port to
30receive the input data that is selected by the filter.
31<p>
32<dt> <var>receive_port_type</var> 
33<dd>
34[in scalar]
35IPC type of the send right provided to the device; either 
36<strong>MACH_MSG_TYPE_MAKE_SEND</strong>, <strong>MACH_MSG_TYPE_MOVE_SEND</strong>,
37or <strong>MACH_MSG_TYPE_COPY_SEND</strong>.
38<p>
39<dt> <var>priority</var> 
40<dd>
41[in scalar]
42Used to order multiple receivers in an implementation
43dependent way.
44<p>
45<dt> <var>filter</var> 
46<dd>
47[pointer to in array of <var>filter_t</var>]
48The address of an array of filter values.
49<p>
50<dt> <var>filter_count</var> 
51<dd>
52[in scalar]
53The size of the <var>filter</var> array (in 16-bit values).
54</dl>
55<h3>DESCRIPTION</h3>
56<p>
57The <strong>device_set_filter</strong> function provides a means by
58which selected data
59appearing at a device interface can be selected and routed to
60a port.  This service is
61provided in support of network devices.
62<p>
63The filter command list consists of an array of up to <strong>NET_MAX_FILTER</strong> 
64(16-bit) values to be applied to incoming data "messages" to determine if 
65that data should be given to a particular input filter. 
66<p>
67Each filter command list specifies a sequence of actions which leave a boolean 
68value on the top of an internal stack.  Each 16-bit value of the command list
69specifies a data (push) operation (high order <strong>NETF_NBPO</strong>
70bits) as well as a binary operator (low order <strong>NETF_NBPA</strong> bits).
71<p>
72The value to be pushed onto the stack is chosen as follows:
73<dl>
74<dt> <strong>NETF_PUSHLIT</strong>
75<dd>
76Use the next 16-bit value of the filter as the value.
77<dt> <strong>NETF_PUSHZERO</strong>
78<dd>
79Use 0 as the value.
80<dt> <strong>NETF_PUSHWORD+</strong><var>N</var>
81<dd>
82Use 16-bit value <var>N</var> of the "data" portion of the message as the value.
83<dt> <strong>NETF_PUSHHDR+</strong><var>N</var>
84<dd>
85Use 16-bit value <var>N</var> of the "header" portion of the message as the value.
86<dt> <strong>NETF_PUSHIND</strong>
87<dd>
88Pops the top 32-bit value from the stack and then uses it to index the 
8916-bit value of the "data" portion of the message to be used as the
90value.
91<dt> <strong>NETF_PUSHHDRIND</strong>
92<dd>
93Pops the top 32-bit value from the stack and then uses it to index the 
9416-bit value of the "header" portion of the message to be used as the 
95value.
96<dt> <strong>NETF_PUSHSTK+</strong><var>N</var>
97<dd>
98Use 32-bit value <var>N</var> of the stack (where the top of stack is value 0) as 
99the value.
100<dt> <strong>NETF_NOPUSH</strong>
101<dd>
102Don't push a value.
103</dl>
104The unsigned value so chosen is promoted to a 32-bit value before being pushed.
105<p>
106Once a value is pushed (except for the case of <strong>NETF_NOPUSH</strong>), the top two 
10732-bit values of the stack are popped and a binary operator applied to them 
108(with the old top of stack as the second operand).  The result
109of the operator is 
110pushed on the stack.  These operators are:
111<dl>
112<dt> <strong>NETF_NOP</strong>
113<dd>
114Don't pop off any values and do no operation.
115<dt> <strong>NETF_EQ</strong>
116<dd>
117Perform an equal comparison.
118<dt> <strong>NETF_LT</strong>
119<dd>
120Perform a less than comparison.
121<dt> <strong>NETF_LE</strong>
122<dd>
123Perform a less than or equal comparison.
124<dt> <strong>NETF_GT</strong>
125<dd>
126Perform a greater than comparison.
127<dt> <strong>NETF_GE</strong>
128<dd>
129Perform a greater than or equal comparison.
130<dt> <strong>NETF_AND</strong>
131<dd>
132Perform a bit-wise boolean AND operation.
133<dt> <strong>NETF_OR</strong>
134<dd>
135Perform a bit-wise boolean inclusive OR operation.
136<dt> <strong>NETF_XOR</strong>
137<dd>
138Perform a bit-wise boolean exclusive OR operation.
139<dt> <strong>NETF_NEQ</strong>
140<dd>
141Perform a not equal comparison.
142<dt> <strong>NETF_LSH</strong>
143<dd>
144Perform a left shift operation.
145<dt> <strong>NETF_RSH</strong>
146<dd>
147Perform a right shift operation.
148<dt> <strong>NETF_ADD</strong>
149<dd>
150Perform an addition.
151<dt> <strong>NETF_SUB</strong>
152<dd>
153Perform a subtraction.
154<dt> <strong>NETF_COR</strong>
155<dd>
156Perform an equal comparison.  If the comparison is <strong>TRUE</strong>, terminate 
157the filter list.  Otherwise, pop the result of the comparison off the stack.
158<dt> <strong>NETF_CAND</strong>
159<dd>
160Perform an equal comparison.  If the comparison is <strong>FALSE</strong>, terminate 
161the filter list.  Otherwise, pop the result of the comparison off the stack.
162<dt> <strong>NETF_CNOR</strong>
163<dd>
164Perform a not equal comparison.  If the comparison is <strong>FALSE</strong>,
165terminate the filter list.  Otherwise, pop the result of the
166comparison off the 
167stack.
168<dt> <strong>NETF_CNAND</strong>
169<dd>
170Perform a not equal comparison.  If the comparison is <strong>TRUE</strong>, terminate 
171the filter list.  Otherwise, pop the result of the comparison off the stack.
172</dl>
173The scan of the filter list terminates when the filter list is emptied, or a
174<strong>NETF_C</strong> operation terminates the list.  At this time, if the final 
175value of the top of the stack is <strong>TRUE</strong>, then the message is accepted
176for the filter.
177<h3>RETURN VALUES</h3>
178<dl>
179<p>
180<dt> <strong>D_DEVICE_DOWN</strong>
181<dd>
182Device has been shut down
183<p>
184<dt> <strong>D_INVALID_OPERATION</strong>
185<dd>
186No filter port was supplied.
187<p>
188<dt> <strong>D_NO_SUCH_DEVICE</strong>
189<dd>
190No device with that name, or the device is not operational.
191</dl>
192<h3>RELATED INFORMATION</h3>
193<p>
194Currently no references.
195