2 #include "wilc_msgqueue.h"
3 #include <linux/spinlock.h>
4 #include "linux_wlan_common.h"
5 #include <linux/errno.h>
6 #include <linux/slab.h>
11 * @note copied from FLO glue implementatuion
14 int wilc_mq_create(struct message_queue *mq)
16 spin_lock_init(&mq->lock);
17 sema_init(&mq->sem, 0);
27 * @note copied from FLO glue implementatuion
30 int wilc_mq_destroy(struct message_queue *mq)
34 /* Release any waiting receiver thread. */
35 while (mq->recv_count > 0) {
40 while (mq->msg_list) {
41 struct message *msg = mq->msg_list->next;
53 * @note copied from FLO glue implementatuion
56 int wilc_mq_send(struct message_queue *mq,
57 const void *send_buf, u32 send_buf_size)
60 struct message *new_msg = NULL;
62 if ((!mq) || (send_buf_size == 0) || (!send_buf)) {
63 PRINT_ER("mq or send_buf is null\n");
68 PRINT_ER("mq fail\n");
72 /* construct a new message */
73 new_msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
77 new_msg->len = send_buf_size;
79 new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
85 spin_lock_irqsave(&mq->lock, flags);
87 /* add it to the message queue */
89 mq->msg_list = new_msg;
91 struct message *tail_msg = mq->msg_list;
93 while (tail_msg->next)
94 tail_msg = tail_msg->next;
96 tail_msg->next = new_msg;
99 spin_unlock_irqrestore(&mq->lock, flags);
109 * @note copied from FLO glue implementatuion
112 int wilc_mq_recv(struct message_queue *mq,
113 void *recv_buf, u32 recv_buf_size, u32 *recv_len)
115 struct message *pstrMessage;
118 if ((!mq) || (recv_buf_size == 0)
119 || (!recv_buf) || (!recv_len)) {
120 PRINT_ER("mq or recv_buf is null\n");
125 PRINT_ER("mq fail\n");
129 spin_lock_irqsave(&mq->lock, flags);
131 spin_unlock_irqrestore(&mq->lock, flags);
134 spin_lock_irqsave(&mq->lock, flags);
136 pstrMessage = mq->msg_list;
138 spin_unlock_irqrestore(&mq->lock, flags);
139 PRINT_ER("pstrMessage is null\n");
142 /* check buffer size */
143 if (recv_buf_size < pstrMessage->len) {
144 spin_unlock_irqrestore(&mq->lock, flags);
146 PRINT_ER("recv_buf_size overflow\n");
150 /* consume the message */
152 memcpy(recv_buf, pstrMessage->buf, pstrMessage->len);
153 *recv_len = pstrMessage->len;
155 mq->msg_list = pstrMessage->next;
157 kfree(pstrMessage->buf);
160 spin_unlock_irqrestore(&mq->lock, flags);