2 * Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
32 #include "../if_medium.h"
36 hal_tx_proc(void *arg, int npending)
38 struct wtap_hal *hal = (struct wtap_hal *)arg;
42 DWTAP_PRINTF("%s\n", __func__);
45 hal = (struct wtap_hal *)arg;
47 p = medium_get_next_packet(hal->hal_md);
51 hal->plugin->work(hal->plugin, p);
54 DWTAP_PRINTF("[%d] freeing m=%p\n", p->id, p->m);
57 free(p, M_WTAP_PACKET);
62 init_hal(struct wtap_hal *hal)
65 DWTAP_PRINTF("%s\n", __func__);
66 mtx_init(&hal->hal_mtx, "wtap_hal mtx", NULL, MTX_DEF | MTX_RECURSE);
68 hal->hal_md = (struct wtap_medium *)malloc(sizeof(struct wtap_medium),
69 M_WTAP, M_NOWAIT | M_ZERO);
70 bzero(hal->hal_md, sizeof(struct wtap_medium));
72 init_medium(hal->hal_md);
73 /* register event handler for packets */
74 TASK_INIT(&hal->hal_md->tx_handler->proc, 0, hal_tx_proc, hal);
78 register_plugin(struct wtap_hal *hal, struct wtap_plugin *plugin)
86 deregister_plugin(struct wtap_hal *hal)
89 hal->plugin->deinit(hal->plugin);
90 hal->plugin = NULL; /* catch illegal usages */
94 deinit_hal(struct wtap_hal *hal)
97 DWTAP_PRINTF("%s\n", __func__);
98 deinit_medium(hal->hal_md);
99 free(hal->hal_md, M_WTAP);
100 mtx_destroy(&hal->hal_mtx);
104 new_wtap(struct wtap_hal *hal, int32_t id)
106 static const uint8_t mac_pool[64][IEEE80211_ADDR_LEN] = {
107 {0,152,154,152,150,151},
108 {0,152,154,152,150,152},
109 {0,152,154,152,150,153},
110 {0,152,154,152,150,154},
111 {0,152,154,152,150,155},
112 {0,152,154,152,150,156},
113 {0,152,154,152,150,157},
114 {0,152,154,152,150,158},
115 {0,152,154,152,151,151},
116 {0,152,154,152,151,152},
117 {0,152,154,152,151,153},
118 {0,152,154,152,151,154},
119 {0,152,154,152,151,155},
120 {0,152,154,152,151,156},
121 {0,152,154,152,151,157},
122 {0,152,154,152,151,158},
123 {0,152,154,152,152,151},
124 {0,152,154,152,152,152},
125 {0,152,154,152,152,153},
126 {0,152,154,152,152,154},
127 {0,152,154,152,152,155},
128 {0,152,154,152,152,156},
129 {0,152,154,152,152,157},
130 {0,152,154,152,152,158},
131 {0,152,154,152,153,151},
132 {0,152,154,152,153,152},
133 {0,152,154,152,153,153},
134 {0,152,154,152,153,154},
135 {0,152,154,152,153,155},
136 {0,152,154,152,153,156},
137 {0,152,154,152,153,157},
138 {0,152,154,152,153,158},
139 {0,152,154,152,154,151},
140 {0,152,154,152,154,152},
141 {0,152,154,152,154,153},
142 {0,152,154,152,154,154},
143 {0,152,154,152,154,155},
144 {0,152,154,152,154,156},
145 {0,152,154,152,154,157},
146 {0,152,154,152,154,158},
147 {0,152,154,152,155,151},
148 {0,152,154,152,155,152},
149 {0,152,154,152,155,153},
150 {0,152,154,152,155,154},
151 {0,152,154,152,155,155},
152 {0,152,154,152,155,156},
153 {0,152,154,152,155,157},
154 {0,152,154,152,155,158},
155 {0,152,154,152,156,151},
156 {0,152,154,152,156,152},
157 {0,152,154,152,156,153},
158 {0,152,154,152,156,154},
159 {0,152,154,152,156,155},
160 {0,152,154,152,156,156},
161 {0,152,154,152,156,157},
162 {0,152,154,152,156,158},
163 {0,152,154,152,157,151},
164 {0,152,154,152,157,152},
165 {0,152,154,152,157,153},
166 {0,152,154,152,157,154},
167 {0,152,154,152,157,155},
168 {0,152,154,152,157,156},
169 {0,152,154,152,157,157},
170 {0,152,154,152,157,158}
173 DWTAP_PRINTF("%s\n", __func__);
174 uint8_t const *macaddr = mac_pool[id];
175 if(hal->hal_devs[id] != NULL){
176 printf("error, wtap_id=%d already created\n", id);
180 hal->hal_devs[id] = (struct wtap_softc *)malloc(
181 sizeof(struct wtap_softc), M_WTAP, M_NOWAIT | M_ZERO);
182 bzero(hal->hal_devs[id], sizeof(struct wtap_softc));
183 hal->hal_devs[id]->sc_md = hal->hal_md;
184 hal->hal_devs[id]->id = id;
185 mtx_init(&hal->hal_devs[id]->sc_mtx, "wtap_softc mtx", NULL,
186 MTX_DEF | MTX_RECURSE);
188 if(wtap_attach(hal->hal_devs[id], macaddr)){
189 printf("%s, cant alloc new wtap\n", __func__);
197 free_wtap(struct wtap_hal *hal, int32_t id)
200 DWTAP_PRINTF("%s\n", __func__);
201 if(hal->hal_devs[id] == NULL){
202 printf("error, wtap_id=%d never created\n", id);
206 if(wtap_detach(hal->hal_devs[id]))
207 printf("%s, cant alloc new wtap\n", __func__);
208 mtx_destroy(&hal->hal_devs[id]->sc_mtx);
209 free(hal->hal_devs[id], M_WTAP);
210 hal->hal_devs[id] = NULL;