HandleControlPacket.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. @file HandleControlPacket.c
  3. This file contains the routines to deal with
  4. sending and receiving of control packets.
  5. */
  6. #include "headers.h"
  7. /**
  8. When a control packet is received, analyze the
  9. "status" and call appropriate response function.
  10. Enqueue the control packet for Application.
  11. @return None
  12. */
  13. static VOID handle_rx_control_packet(PMINI_ADAPTER Adapter, struct sk_buff *skb)
  14. {
  15. PPER_TARANG_DATA pTarang = NULL;
  16. BOOLEAN HighPriorityMessage = FALSE;
  17. struct sk_buff * newPacket = NULL;
  18. CHAR cntrl_msg_mask_bit = 0;
  19. BOOLEAN drop_pkt_flag = TRUE ;
  20. USHORT usStatus = *(PUSHORT)(skb->data);
  21. if (netif_msg_pktdata(Adapter))
  22. print_hex_dump(KERN_DEBUG, PFX "rx control: ", DUMP_PREFIX_NONE,
  23. 16, 1, skb->data, skb->len, 0);
  24. switch(usStatus)
  25. {
  26. case CM_RESPONSES: // 0xA0
  27. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "MAC Version Seems to be Non Multi-Classifier, rejected by Driver");
  28. HighPriorityMessage = TRUE ;
  29. break;
  30. case CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP:
  31. HighPriorityMessage = TRUE ;
  32. if(Adapter->LinkStatus==LINKUP_DONE)
  33. {
  34. CmControlResponseMessage(Adapter,(skb->data +sizeof(USHORT)));
  35. }
  36. break;
  37. case LINK_CONTROL_RESP: //0xA2
  38. case STATUS_RSP: //0xA1
  39. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL,"LINK_CONTROL_RESP");
  40. HighPriorityMessage = TRUE ;
  41. LinkControlResponseMessage(Adapter,(skb->data + sizeof(USHORT)));
  42. break;
  43. case STATS_POINTER_RESP: //0xA6
  44. HighPriorityMessage = TRUE ;
  45. StatisticsResponse(Adapter, (skb->data + sizeof(USHORT)));
  46. break;
  47. case IDLE_MODE_STATUS: //0xA3
  48. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL,"IDLE_MODE_STATUS Type Message Got from F/W");
  49. InterfaceIdleModeRespond(Adapter, (PUINT)(skb->data +
  50. sizeof(USHORT)));
  51. HighPriorityMessage = TRUE ;
  52. break;
  53. case AUTH_SS_HOST_MSG:
  54. HighPriorityMessage = TRUE ;
  55. break;
  56. default:
  57. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL,"Got Default Response");
  58. /* Let the Application Deal with This Packet */
  59. break;
  60. }
  61. //Queue The Control Packet to The Application Queues
  62. down(&Adapter->RxAppControlQueuelock);
  63. for (pTarang = Adapter->pTarangs; pTarang; pTarang = pTarang->next)
  64. {
  65. if(Adapter->device_removed)
  66. {
  67. break;
  68. }
  69. drop_pkt_flag = TRUE ;
  70. /*
  71. There are cntrl msg from A0 to AC. It has been mapped to 0 to C bit in the cntrl mask.
  72. Also, by default AD to BF has been masked to the rest of the bits... which wil be ON by default.
  73. if mask bit is enable to particular pkt status, send it out to app else stop it.
  74. */
  75. cntrl_msg_mask_bit = (usStatus & 0x1F);
  76. //printk("\ninew msg mask bit which is disable in mask:%X", cntrl_msg_mask_bit);
  77. if(pTarang->RxCntrlMsgBitMask & (1<<cntrl_msg_mask_bit))
  78. drop_pkt_flag = FALSE;
  79. if ((drop_pkt_flag == TRUE) || (pTarang->AppCtrlQueueLen > MAX_APP_QUEUE_LEN) ||
  80. ((pTarang->AppCtrlQueueLen > MAX_APP_QUEUE_LEN/2) && (HighPriorityMessage == FALSE)))
  81. {
  82. /*
  83. Assumption:-
  84. 1. every tarang manages it own dropped pkt statitistics
  85. 2. Total packet dropped per tarang will be equal to the sum of all types of dropped
  86. pkt by that tarang only.
  87. */
  88. switch(*(PUSHORT)skb->data)
  89. {
  90. case CM_RESPONSES:
  91. pTarang->stDroppedAppCntrlMsgs.cm_responses++;
  92. break;
  93. case CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP:
  94. pTarang->stDroppedAppCntrlMsgs.cm_control_newdsx_multiclassifier_resp++;
  95. break;
  96. case LINK_CONTROL_RESP:
  97. pTarang->stDroppedAppCntrlMsgs.link_control_resp++;
  98. break;
  99. case STATUS_RSP:
  100. pTarang->stDroppedAppCntrlMsgs.status_rsp++;
  101. break;
  102. case STATS_POINTER_RESP:
  103. pTarang->stDroppedAppCntrlMsgs.stats_pointer_resp++;
  104. break;
  105. case IDLE_MODE_STATUS:
  106. pTarang->stDroppedAppCntrlMsgs.idle_mode_status++ ;
  107. break;
  108. case AUTH_SS_HOST_MSG:
  109. pTarang->stDroppedAppCntrlMsgs.auth_ss_host_msg++ ;
  110. break;
  111. default:
  112. pTarang->stDroppedAppCntrlMsgs.low_priority_message++ ;
  113. break;
  114. }
  115. continue;
  116. }
  117. newPacket = skb_clone(skb, GFP_KERNEL);
  118. if (!newPacket)
  119. break;
  120. ENQUEUEPACKET(pTarang->RxAppControlHead,pTarang->RxAppControlTail,
  121. newPacket);
  122. pTarang->AppCtrlQueueLen++;
  123. }
  124. up(&Adapter->RxAppControlQueuelock);
  125. wake_up(&Adapter->process_read_wait_queue);
  126. dev_kfree_skb(skb);
  127. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "After wake_up_interruptible");
  128. }
  129. /**
  130. @ingroup ctrl_pkt_functions
  131. Thread to handle control pkt reception
  132. */
  133. int control_packet_handler (PMINI_ADAPTER Adapter /**< pointer to adapter object*/
  134. )
  135. {
  136. struct sk_buff *ctrl_packet= NULL;
  137. unsigned long flags = 0;
  138. //struct timeval tv ;
  139. //int *puiBuffer = NULL ;
  140. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "Entering to make thread wait on control packet event!");
  141. while(1)
  142. {
  143. wait_event_interruptible(Adapter->process_rx_cntrlpkt,
  144. atomic_read(&Adapter->cntrlpktCnt) ||
  145. Adapter->bWakeUpDevice ||
  146. kthread_should_stop()
  147. );
  148. if(kthread_should_stop())
  149. {
  150. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "Exiting \n");
  151. return 0;
  152. }
  153. if(TRUE == Adapter->bWakeUpDevice)
  154. {
  155. Adapter->bWakeUpDevice = FALSE;
  156. if((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) &&
  157. ((TRUE == Adapter->IdleMode)|| (TRUE == Adapter->bShutStatus)))
  158. {
  159. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "Calling InterfaceAbortIdlemode\n");
  160. // Adapter->bTriedToWakeUpFromlowPowerMode = TRUE;
  161. InterfaceIdleModeWakeup (Adapter);
  162. }
  163. continue;
  164. }
  165. while(atomic_read(&Adapter->cntrlpktCnt))
  166. {
  167. spin_lock_irqsave(&Adapter->control_queue_lock, flags);
  168. ctrl_packet = Adapter->RxControlHead;
  169. if(ctrl_packet)
  170. {
  171. DEQUEUEPACKET(Adapter->RxControlHead,Adapter->RxControlTail);
  172. // Adapter->RxControlHead=ctrl_packet->next;
  173. }
  174. spin_unlock_irqrestore (&Adapter->control_queue_lock, flags);
  175. handle_rx_control_packet(Adapter, ctrl_packet);
  176. atomic_dec(&Adapter->cntrlpktCnt);
  177. }
  178. SetUpTargetDsxBuffers(Adapter);
  179. }
  180. return STATUS_SUCCESS;
  181. }
  182. INT flushAllAppQ(void)
  183. {
  184. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
  185. PPER_TARANG_DATA pTarang = NULL;
  186. struct sk_buff *PacketToDrop = NULL;
  187. for(pTarang = Adapter->pTarangs; pTarang; pTarang = pTarang->next)
  188. {
  189. while(pTarang->RxAppControlHead != NULL)
  190. {
  191. PacketToDrop=pTarang->RxAppControlHead;
  192. DEQUEUEPACKET(pTarang->RxAppControlHead,pTarang->RxAppControlTail);
  193. dev_kfree_skb(PacketToDrop);
  194. }
  195. pTarang->AppCtrlQueueLen = 0;
  196. //dropped contrl packet statistics also should be reset.
  197. memset((PVOID)&pTarang->stDroppedAppCntrlMsgs, 0, sizeof(S_MIBS_DROPPED_APP_CNTRL_MESSAGES));
  198. }
  199. return STATUS_SUCCESS ;
  200. }