|
3 | 3 | #include <linux/kthread.h>
|
4 | 4 | #include <linux/delay.h>
|
5 | 5 | #include <linux/completion.h>
|
| 6 | +#include <linux/list.h> |
6 | 7 | #include "host_interface.h"
|
| 8 | +#include <linux/spinlock.h> |
| 9 | +#include <linux/errno.h> |
7 | 10 | #include "coreconfigurator.h"
|
8 | 11 | #include "wilc_wlan.h"
|
9 | 12 | #include "wilc_wlan_if.h"
|
10 |
| -#include "wilc_msgqueue.h" |
11 | 13 | #include <linux/etherdevice.h>
|
12 | 14 | #include "wilc_wfi_netdevice.h"
|
13 | 15 |
|
|
57 | 59 | #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
|
58 | 60 | #define DEFAULT_LINK_SPEED 72
|
59 | 61 |
|
| 62 | +struct message { |
| 63 | + void *buf; |
| 64 | + u32 len; |
| 65 | + struct list_head list; |
| 66 | +}; |
| 67 | + |
| 68 | +struct message_queue { |
| 69 | + struct semaphore sem; |
| 70 | + spinlock_t lock; |
| 71 | + bool exiting; |
| 72 | + u32 recv_count; |
| 73 | + struct list_head msg_list; |
| 74 | +}; |
| 75 | + |
60 | 76 | struct host_if_wpa_attr {
|
61 | 77 | u8 *key;
|
62 | 78 | const u8 *mac_addr;
|
@@ -263,6 +279,151 @@ static struct wilc_vif *join_req_vif;
|
263 | 279 | static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
|
264 | 280 | static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
|
265 | 281 | static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
|
| 282 | +static int wilc_mq_create(struct message_queue *mq); |
| 283 | +static int wilc_mq_send(struct message_queue *mq, |
| 284 | + const void *send_buf, u32 send_buf_size); |
| 285 | +static int wilc_mq_recv(struct message_queue *mq, |
| 286 | + void *recv_buf, u32 recv_buf_size, u32 *recv_len); |
| 287 | +static int wilc_mq_destroy(struct message_queue *mq); |
| 288 | + |
| 289 | +/*! |
| 290 | + * @author syounan |
| 291 | + * @date 1 Sep 2010 |
| 292 | + * @note copied from FLO glue implementatuion |
| 293 | + * @version 1.0 |
| 294 | + */ |
| 295 | +static int wilc_mq_create(struct message_queue *mq) |
| 296 | +{ |
| 297 | + spin_lock_init(&mq->lock); |
| 298 | + sema_init(&mq->sem, 0); |
| 299 | + INIT_LIST_HEAD(&mq->msg_list); |
| 300 | + mq->recv_count = 0; |
| 301 | + mq->exiting = false; |
| 302 | + return 0; |
| 303 | +} |
| 304 | + |
| 305 | +/*! |
| 306 | + * @author syounan |
| 307 | + * @date 1 Sep 2010 |
| 308 | + * @note copied from FLO glue implementatuion |
| 309 | + * @version 1.0 |
| 310 | + */ |
| 311 | +static int wilc_mq_destroy(struct message_queue *mq) |
| 312 | +{ |
| 313 | + struct message *msg; |
| 314 | + |
| 315 | + mq->exiting = true; |
| 316 | + |
| 317 | + /* Release any waiting receiver thread. */ |
| 318 | + while (mq->recv_count > 0) { |
| 319 | + up(&mq->sem); |
| 320 | + mq->recv_count--; |
| 321 | + } |
| 322 | + |
| 323 | + while (!list_empty(&mq->msg_list)) { |
| 324 | + msg = list_first_entry(&mq->msg_list, struct message, list); |
| 325 | + list_del(&msg->list); |
| 326 | + kfree(msg->buf); |
| 327 | + } |
| 328 | + |
| 329 | + return 0; |
| 330 | +} |
| 331 | + |
| 332 | +/*! |
| 333 | + * @author syounan |
| 334 | + * @date 1 Sep 2010 |
| 335 | + * @note copied from FLO glue implementatuion |
| 336 | + * @version 1.0 |
| 337 | + */ |
| 338 | +static int wilc_mq_send(struct message_queue *mq, |
| 339 | + const void *send_buf, u32 send_buf_size) |
| 340 | +{ |
| 341 | + unsigned long flags; |
| 342 | + struct message *new_msg = NULL; |
| 343 | + |
| 344 | + if (!mq || (send_buf_size == 0) || !send_buf) |
| 345 | + return -EINVAL; |
| 346 | + |
| 347 | + if (mq->exiting) |
| 348 | + return -EFAULT; |
| 349 | + |
| 350 | + /* construct a new message */ |
| 351 | + new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC); |
| 352 | + if (!new_msg) |
| 353 | + return -ENOMEM; |
| 354 | + |
| 355 | + new_msg->len = send_buf_size; |
| 356 | + INIT_LIST_HEAD(&new_msg->list); |
| 357 | + new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC); |
| 358 | + if (!new_msg->buf) { |
| 359 | + kfree(new_msg); |
| 360 | + return -ENOMEM; |
| 361 | + } |
| 362 | + |
| 363 | + spin_lock_irqsave(&mq->lock, flags); |
| 364 | + |
| 365 | + /* add it to the message queue */ |
| 366 | + list_add_tail(&new_msg->list, &mq->msg_list); |
| 367 | + |
| 368 | + spin_unlock_irqrestore(&mq->lock, flags); |
| 369 | + |
| 370 | + up(&mq->sem); |
| 371 | + |
| 372 | + return 0; |
| 373 | +} |
| 374 | + |
| 375 | +/*! |
| 376 | + * @author syounan |
| 377 | + * @date 1 Sep 2010 |
| 378 | + * @note copied from FLO glue implementatuion |
| 379 | + * @version 1.0 |
| 380 | + */ |
| 381 | +static int wilc_mq_recv(struct message_queue *mq, |
| 382 | + void *recv_buf, u32 recv_buf_size, u32 *recv_len) |
| 383 | +{ |
| 384 | + struct message *msg; |
| 385 | + unsigned long flags; |
| 386 | + |
| 387 | + if (!mq || (recv_buf_size == 0) || !recv_buf || !recv_len) |
| 388 | + return -EINVAL; |
| 389 | + |
| 390 | + if (mq->exiting) |
| 391 | + return -EFAULT; |
| 392 | + |
| 393 | + spin_lock_irqsave(&mq->lock, flags); |
| 394 | + mq->recv_count++; |
| 395 | + spin_unlock_irqrestore(&mq->lock, flags); |
| 396 | + |
| 397 | + down(&mq->sem); |
| 398 | + spin_lock_irqsave(&mq->lock, flags); |
| 399 | + |
| 400 | + if (list_empty(&mq->msg_list)) { |
| 401 | + spin_unlock_irqrestore(&mq->lock, flags); |
| 402 | + up(&mq->sem); |
| 403 | + return -EFAULT; |
| 404 | + } |
| 405 | + /* check buffer size */ |
| 406 | + msg = list_first_entry(&mq->msg_list, struct message, list); |
| 407 | + if (recv_buf_size < msg->len) { |
| 408 | + spin_unlock_irqrestore(&mq->lock, flags); |
| 409 | + up(&mq->sem); |
| 410 | + return -EOVERFLOW; |
| 411 | + } |
| 412 | + |
| 413 | + /* consume the message */ |
| 414 | + mq->recv_count--; |
| 415 | + memcpy(recv_buf, msg->buf, msg->len); |
| 416 | + *recv_len = msg->len; |
| 417 | + |
| 418 | + list_del(&msg->list); |
| 419 | + |
| 420 | + kfree(msg->buf); |
| 421 | + kfree(msg); |
| 422 | + |
| 423 | + spin_unlock_irqrestore(&mq->lock, flags); |
| 424 | + |
| 425 | + return 0; |
| 426 | +} |
266 | 427 |
|
267 | 428 | /* The u8IfIdx starts from 0 to NUM_CONCURRENT_IFC -1, but 0 index used as
|
268 | 429 | * special purpose in wilc device, so we add 1 to the index to starts from 1.
|
|
0 commit comments