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 *pvSendBuffer, u32 u32SendBufferSize)
60 struct message *pstrMessage = NULL;
62 if ((!mq) || (u32SendBufferSize == 0) || (!pvSendBuffer)) {
63 PRINT_ER("mq or pvSendBuffer is null\n");
68 PRINT_ER("mq fail\n");
72 /* construct a new message */
73 pstrMessage = kmalloc(sizeof(struct message), GFP_ATOMIC);
77 pstrMessage->len = u32SendBufferSize;
78 pstrMessage->next = NULL;
79 pstrMessage->buf = kmemdup(pvSendBuffer, u32SendBufferSize,
81 if (!pstrMessage->buf) {
86 spin_lock_irqsave(&mq->lock, flags);
88 /* add it to the message queue */
90 mq->msg_list = pstrMessage;
92 struct message *pstrTailMsg = mq->msg_list;
94 while (pstrTailMsg->next)
95 pstrTailMsg = pstrTailMsg->next;
97 pstrTailMsg->next = pstrMessage;
100 spin_unlock_irqrestore(&mq->lock, flags);
110 * @note copied from FLO glue implementatuion
113 int wilc_mq_recv(struct message_queue *pHandle,
114 void *pvRecvBuffer, u32 u32RecvBufferSize,
115 u32 *pu32ReceivedLength)
117 struct message *pstrMessage;
120 if ((!pHandle) || (u32RecvBufferSize == 0)
121 || (!pvRecvBuffer) || (!pu32ReceivedLength)) {
122 PRINT_ER("pHandle or pvRecvBuffer is null\n");
126 if (pHandle->exiting) {
127 PRINT_ER("pHandle fail\n");
131 spin_lock_irqsave(&pHandle->lock, flags);
132 pHandle->recv_count++;
133 spin_unlock_irqrestore(&pHandle->lock, flags);
136 spin_lock_irqsave(&pHandle->lock, flags);
138 pstrMessage = pHandle->msg_list;
140 spin_unlock_irqrestore(&pHandle->lock, flags);
141 PRINT_ER("pstrMessage is null\n");
144 /* check buffer size */
145 if (u32RecvBufferSize < pstrMessage->len) {
146 spin_unlock_irqrestore(&pHandle->lock, flags);
148 PRINT_ER("u32RecvBufferSize overflow\n");
152 /* consume the message */
153 pHandle->recv_count--;
154 memcpy(pvRecvBuffer, pstrMessage->buf, pstrMessage->len);
155 *pu32ReceivedLength = pstrMessage->len;
157 pHandle->msg_list = pstrMessage->next;
159 kfree(pstrMessage->buf);
162 spin_unlock_irqrestore(&pHandle->lock, flags);