hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * This module is designed to collect internal diagnostic information.
 *
 *    Author: Cosa
 *    History: Created at 2023/02/03
 */
#define _PHL_DIAGNOSE_C_
#include "phl_headers.h"
 
#ifdef CONFIG_PHL_DIAGNOSE
 
static void _diag_evt_done(void* priv, struct phl_msg* msg)
{
   struct phl_info_t *phl_info = (struct phl_info_t *)priv;
 
   if (msg->inbuf && msg->inlen) {
       _os_kmem_free(phl_to_drvpriv(phl_info),
           msg->inbuf, msg->inlen);
   }
}
 
bool rtw_phl_send_diag_hub_msg(struct rtw_phl_com_t *phl_com,
       u16 phl_evt, u8 sub_evt, u8 level, u8 ver, u8 *buf, u32 len)
{
   struct phl_msg msg = {0};
   struct phl_msg_attribute attr = {0};
   struct phl_info_t *phl = NULL;
   struct rtw_phl_diag_msg *dmsg = NULL;
   void *d = NULL;
 
   if (!phl_com || !buf)
       return false;
 
   phl = phl_com->phl_priv;
 
   if ((phl_evt >= PHL_DIAG_EVT_MAX) ||(level >= PHL_DIAG_LVL_MAX) ||
       (len > MAX_PHL_DIAG_MSG_LEN) || !phl)  {
       return false;
   }
 
   d = phl_to_drvpriv(phl);
   if (!d)
       return false;
 
   dmsg = (struct rtw_phl_diag_msg *)_os_kmem_alloc(
           d, sizeof(struct rtw_phl_diag_msg));
   if (!dmsg)
       return false;
 
   SET_MSG_MDL_ID_FIELD(msg.msg_id, PHL_MDL_GENERAL);
   SET_MSG_EVT_ID_FIELD(msg.msg_id, MSG_EVT_DIAGNOSTIC);
 
   dmsg->type = phl_evt;
   dmsg->level = level;
   if (phl_evt == PHL_DIAG_EVT_MAC || phl_evt == PHL_DIAG_EVT_BB ||
       phl_evt == PHL_DIAG_EVT_RF) {
       dmsg->sub_evt = sub_evt;
   } else {
       dmsg->sub_evt = INVALID_SUBMODULE_DIAG_EVT;
   }
   dmsg->ver = ver;
   dmsg->len = len;
   _os_mem_cpy(d, dmsg->buf, buf, len);
 
   msg.inbuf = (u8 *)dmsg;
   msg.inlen = sizeof(struct rtw_phl_diag_msg);
   attr.completion.completion = _diag_evt_done;
   attr.completion.priv = phl;
 
   if (phl_msg_hub_send(phl, &attr, &msg) != RTW_PHL_STATUS_SUCCESS) {
       _os_kmem_free(d, dmsg, sizeof(struct rtw_phl_diag_msg));
       return false;
   } else {
       return true;
   }
}
 
#endif