wlan: Feature P2P Debugging logging

1. Parsing action frame to string.
2. Printing connection status of P2P to find where connection is failed.

Change-Id: Ifa618efeb38aa55bbcd7265cec966d847cd0bfce
CR-Fixed: 412883
diff --git a/CORE/HDD/inc/wlan_hdd_p2p.h b/CORE/HDD/inc/wlan_hdd_p2p.h
index f4d8cc3..ff845cd 100644
--- a/CORE/HDD/inc/wlan_hdd_p2p.h
+++ b/CORE/HDD/inc/wlan_hdd_p2p.h
@@ -57,6 +57,21 @@
 #define P2P_POWER_SAVE_TYPE_PERIODIC_NOA         1 << 1;
 #define P2P_POWER_SAVE_TYPE_SINGLE_NOA           1 << 2;
 
+#ifdef WLAN_FEATURE_P2P_DEBUG
+typedef enum  { P2P_NOT_ACTIVE,
+                P2P_GO_NEG_PROCESS,
+                P2P_GO_NEG_COMPLETED,
+                P2P_CLIENT_CONNECTING_STATE_1,
+                P2P_GO_COMPLETED_STATE,
+                P2P_CLIENT_CONNECTED_STATE_1,
+                P2P_CLIENT_DISCONNECTED_STATE,
+                P2P_CLIENT_CONNECTING_STATE_2,
+                P2P_CLIENT_COMPLETED_STATE
+               }tP2PConnectionStatus;
+
+extern tP2PConnectionStatus globalP2PConnectionStatus;
+#endif
+
 typedef struct p2p_app_setP2pPs{
    tANI_U8     opp_ps;
    tANI_U32     ctWindow;
diff --git a/CORE/HDD/src/wlan_hdd_assoc.c b/CORE/HDD/src/wlan_hdd_assoc.c
index dd15461..7195863 100644
--- a/CORE/HDD/src/wlan_hdd_assoc.c
+++ b/CORE/HDD/src/wlan_hdd_assoc.c
@@ -533,6 +533,24 @@
         memcpy(wrqu.ap_addr.sa_data, pCsrRoamInfo->pBssDesc->bssId, sizeof(pCsrRoamInfo->pBssDesc->bssId));
         type = WLAN_STA_ASSOC_DONE_IND;
 
+#ifdef WLAN_FEATURE_P2P_DEBUG
+        if(pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
+        {
+             if(globalP2PConnectionStatus == P2P_CLIENT_CONNECTING_STATE_1)
+             {
+                 globalP2PConnectionStatus = P2P_CLIENT_CONNECTED_STATE_1;
+                 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
+                                "Connecting state to Connected State for 8-way "
+                                "Handshake");
+             }
+             else if(globalP2PConnectionStatus == P2P_CLIENT_CONNECTING_STATE_2)
+             {
+                 globalP2PConnectionStatus = P2P_CLIENT_COMPLETED_STATE;
+                 hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
+                           "Connecting state to P2P Client Connection Completed");
+             }
+        }
+#endif
         pr_info("wlan: connected to %02x:%02x:%02x:%02x:%02x:%02x\n",
                       wrqu.ap_addr.sa_data[0],
                       wrqu.ap_addr.sa_data[1],
@@ -677,6 +695,24 @@
             hddLog(VOS_TRACE_LEVEL_INFO_HIGH, 
                     "%s: sent disconnected event to nl80211", 
                     __func__);
+#ifdef WLAN_FEATURE_P2P_DEBUG
+            if(pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
+            {
+                if(globalP2PConnectionStatus == P2P_CLIENT_CONNECTED_STATE_1)
+                {
+                    globalP2PConnectionStatus = P2P_CLIENT_DISCONNECTED_STATE;
+                    hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] 8 way Handshake completed "
+                          "and moved to disconnected state");
+                }
+                else if(globalP2PConnectionStatus == P2P_CLIENT_COMPLETED_STATE)
+                {
+                    globalP2PConnectionStatus = P2P_NOT_ACTIVE;
+                    hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] P2P Client is removed "
+                          "and moved to inactive state");
+                }
+            }
+#endif
+
             /* To avoid wpa_supplicant sending "HANGED" CMD to ICS UI */
             if( eCSR_ROAM_LOSTLINK == roamStatus )
             {
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 1926017..dde55ae 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -1591,6 +1591,24 @@
     //Succesfully started Bss update the state bit.
     set_bit(SOFTAP_BSS_STARTED, &pHostapdAdapter->event_flags);
 
+#ifdef WLAN_FEATURE_P2P_DEBUG
+    if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
+    {
+         if(globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED)
+         {
+             globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
+             hddLog(LOGE,"[P2P State] From Go nego completed to "
+                         "Non-autonomus Group started");
+         }
+         else if(globalP2PConnectionStatus == P2P_NOT_ACTIVE)
+         {
+             globalP2PConnectionStatus = P2P_GO_COMPLETED_STATE;
+             hddLog(LOGE,"[P2P State] From Inactive to "
+                         "Autonomus Group started");
+         }
+    }
+#endif
+
     pHostapdState->bCommit = TRUE;
     EXIT();
 
@@ -1842,6 +1860,15 @@
 
         pAdapter->sessionCtx.ap.beacon = NULL;
         kfree(old);
+#ifdef WLAN_FEATURE_P2P_DEBUG
+        if((pAdapter->device_mode == WLAN_HDD_P2P_GO) &&
+           (globalP2PConnectionStatus == P2P_GO_COMPLETED_STATE))
+        {
+            hddLog(LOGE,"[P2P State] From GO completed to Inactive state "
+                        "GO got removed");
+            globalP2PConnectionStatus = P2P_NOT_ACTIVE;
+        }
+#endif
     }
     EXIT();
     return status;
@@ -3854,6 +3881,28 @@
                                                        request->ie_len);
             if (pP2pIe != NULL)
             {
+#ifdef WLAN_FEATURE_P2P_DEBUG
+                if (((globalP2PConnectionStatus == P2P_GO_NEG_COMPLETED) ||
+                    (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS)) &&
+                    (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
+                {
+                    globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_1;
+                    hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
+                                    "Go nego completed to Connection is started");
+                    hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
+                                   "for 8way Handshake");
+                }
+                else if((globalP2PConnectionStatus == P2P_CLIENT_DISCONNECTED_STATE) &&
+                        (WLAN_HDD_P2P_CLIENT == pAdapter->device_mode))
+                {
+                    globalP2PConnectionStatus = P2P_CLIENT_CONNECTING_STATE_2;
+                    hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P State] Changing state from "
+                                    "Disconnected state to Connection is started");
+                    hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P]P2P Scanning is started "
+                                                        "for 4way Handshake");
+                }
+#endif
+
                 /* no_cck will be set during p2p find to disable 11b rates */
                 if(TRUE == request->no_cck)
                 {
diff --git a/CORE/HDD/src/wlan_hdd_p2p.c b/CORE/HDD/src/wlan_hdd_p2p.c
index 6d319c0..06f39bd 100644
--- a/CORE/HDD/src/wlan_hdd_p2p.c
+++ b/CORE/HDD/src/wlan_hdd_p2p.c
@@ -44,6 +44,27 @@
 #include <linux/etherdevice.h>
 #include <net/ieee80211_radiotap.h>
 
+#ifdef WLAN_FEATURE_P2P_DEBUG
+#define MAX_P2P_ACTION_FRAME_TYPE 9
+const char *p2p_action_frame_type[]={"GO Negotiation Request",
+                                     "GO Negotiation Response",
+                                     "GO Negotiation Confirmation",
+                                     "P2P Invitation Request",
+                                     "P2P Invitation Response",
+                                     "Device Discoverability Request",
+                                     "Device Discoverability Response",
+                                     "Provision Discovery Request",
+                                     "Provision Discovery Response"};
+
+/* We no need to protect this variable since
+ * there is no chance of race to condition
+ * and also not make any complicating the code
+ * just for debugging log
+ */
+tP2PConnectionStatus globalP2PConnectionStatus = P2P_NOT_ACTIVE;
+
+#endif
+
 extern struct net_device_ops net_ops_struct;
 
 static int hdd_wlan_add_rx_radiotap_hdr( struct sk_buff *skb,
@@ -458,6 +479,39 @@
     hdd_adapter_t *goAdapter;
 #endif
 
+#ifdef WLAN_FEATURE_P2P_DEBUG
+    if ((type == SIR_MAC_MGMT_FRAME) &&
+            (subType == SIR_MAC_MGMT_ACTION) &&
+            (buf[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET] == WLAN_HDD_PUBLIC_ACTION_FRAME))
+    {
+        actionFrmType = buf[WLAN_HDD_PUBLIC_ACTION_FRAME_TYPE_OFFSET];
+        if(actionFrmType > MAX_P2P_ACTION_FRAME_TYPE)
+        {
+            hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P] unknown[%d] ---> OTA",
+                                   actionFrmType);
+        }
+        else
+        {
+            hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P] %s ---> OTA",
+            p2p_action_frame_type[actionFrmType]);
+            if( (actionFrmType == WLAN_HDD_PROV_DIS_REQ) &&
+                (globalP2PConnectionStatus == P2P_NOT_ACTIVE) )
+            {
+                 globalP2PConnectionStatus = P2P_GO_NEG_PROCESS;
+                 hddLog(LOGE,"[P2P State]Inactive state to "
+                            "GO negotation progress state");
+            }
+            else if( (actionFrmType == WLAN_HDD_GO_NEG_CNF) &&
+                (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS) )
+            {
+                 globalP2PConnectionStatus = P2P_GO_NEG_COMPLETED;
+                 hddLog(LOGE,"[P2P State]GO nego progress to GO nego"
+                             " completed state");
+            }
+        }
+    }
+#endif
+
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
     noack = dont_wait_for_ack;
 #endif
@@ -1234,6 +1288,40 @@
     {
         actionFrmType = pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_TYPE_OFFSET];
         hddLog(LOG1, "Rx Action Frame %u \n", actionFrmType);
+#ifdef WLAN_FEATURE_P2P_DEBUG
+        if(actionFrmType > MAX_P2P_ACTION_FRAME_TYPE)
+        {
+            hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P] unknown[%d] <--- OTA",
+                                                        actionFrmType);
+        }
+        else
+        {
+            hddLog(VOS_TRACE_LEVEL_ERROR,"[P2P] %s <--- OTA",
+            p2p_action_frame_type[actionFrmType]);
+            if( (actionFrmType == WLAN_HDD_PROV_DIS_REQ) &&
+                (globalP2PConnectionStatus == P2P_NOT_ACTIVE) )
+            {
+                 globalP2PConnectionStatus = P2P_GO_NEG_PROCESS;
+                 hddLog(LOGE,"[P2P State]Inactive state to "
+                           "GO negotation progress state");
+            }
+            else if( (actionFrmType == WLAN_HDD_GO_NEG_CNF) &&
+                (globalP2PConnectionStatus == P2P_GO_NEG_PROCESS) )
+            {
+                 globalP2PConnectionStatus = P2P_GO_NEG_COMPLETED;
+                 hddLog(LOGE,"[P2P State]GO nego progress to GO nego"
+                             " completed state");
+            }
+            else if( (actionFrmType == WLAN_HDD_INVITATION_REQ) &&
+                (globalP2PConnectionStatus == P2P_NOT_ACTIVE) )
+            {
+                 globalP2PConnectionStatus = P2P_GO_NEG_COMPLETED;
+                 hddLog(LOGE,"[P2P State]Inactive state to GO nego"
+                             " completed state Autonomus GO fromation");
+            }
+        }
+#endif
+
         if (((actionFrmType == WLAN_HDD_PROV_DIS_RESP) &&
                     (cfgState->actionFrmState == HDD_PD_REQ_ACK_PENDING)) ||
                 ((actionFrmType == WLAN_HDD_GO_NEG_RESP) &&