Project

General

Profile

Diag » History » Version 15

laforge, 12/23/2016 03:36 PM

1 4 laforge
{{>toc}}
2
3 1 laforge
h1. Diag
4
5 12 laforge
Qualcomm _Diag_ is the qualcomm diagnostics interface built into many Qualcomm based chipsets (or rather their software) for a long time (more than a decade).  It is not publicly documented, but there are tools from Qualcomm (QPST, QXDM) as well as proprietary third-party tools and some Free Softare projects that implement parts of it.
6
7
The general idea is that there is some physical transport medium between the chipset/modem and an external PC, and the PC can request certain diagnostic information to be sent via that physical transport.  Initially, this transport was a dedicated serial port/UART.  Later, this became a virtual serial port over USB.
8
9
In a single-processor Modem (with only a baseband processor) it is rather simple: Some software on the baseband processor implements the DIAG protocol, and responds to any related requests received on the DIAG port.
10
11
In a multi-processor situation (like the MDM9215/MDM9x07 with their Linux-running Cortex-A5), the situation becomes slightly more complex.  First of all, not only the external host/PC might want to consume DIAG information, but also code on the Linux processor inside the chip.  Furthermore, code in the Linux processor might also want to offer some DIAG information towards the external host/PC.
12
13
The Qualcomm Android Linux kernel (usd even on the non-Android devices) implements several related kernel drivers, see [[Qualcomm_Kernel#diag]]
14
15
In userspace on the Linux inside the modem, there is a (unfortunately again non-free) library called @libdiag@ which offers some convenience API for programs to either consume DIAG or to generate/respond to DIAG received from the host/PC.  Luckily the library is not performing much required functionality, so third-party programs like "SnoopSnitch":https://opensource.srlabs.de/projects/snoopsnitch have managed to talk directly to the @/dev/diag@ kernel device without needing to use that non-free library.
16
17 6 laforge
18 1 laforge
h2. Acronyms
19
20
|DCI|Diag Consumer Interface|
21
22 4 laforge
h2. Child Pages
23
24
{{child_pages()}}
25 6 laforge
26 15 laforge
h2. DIAG Services
27
28
|_.Name|_.Description|
29
|LOG|Diagnostic Log Services|
30
|MSG|Debug Message Service (F3/QSHRINK?)|
31
|EVENT|Diagnostic Events|
32
|PKT|Diagnostic Packet Request/Response|
33
|DCI_LOG|Diag Consumer Interface Logging|
34
|DCI_EVENT|Diag Consumer Interface Events|
35
36 6 laforge
h2. Subsystems
37
38
h3. Logging
39
40
Logging works by so-called log-codes.  The Log code identifies the source/category of the logged information.  Log codes are 16bit unsigned integers.
41
42
|_.Base Code|_.Purpose|
43
|0x1000|CDMA 1x|
44
|0x4000|WCDMA|
45
|0x5000|GSM|
46
|0x6000|Location Based Services|
47
|0x7000|UMTS|
48
|0x8000|TDMA|
49
|0xA000|DTV|
50
|0xB000|APPS|
51
|0xB010|LTE (until 0xB1FF)|
52
|0xB400|WIMAX|
53
|0xC000|DSP|
54
|0xD000|TD-SCDMA (until 0xD1FF)|
55
|0xF000|LOG TOOLS|
56 4 laforge
57 3 laforge
h2. Kernel support
58
59 1 laforge
See [[Qualcomm_Kernel#diag]]
60
61 4 laforge
h2. Library
62 1 laforge
63 4 laforge
There is @/usr/lib/libdiag.so.1@ which is linked by virtually any Qualcomm or Quectel proprietary program running on the Linux in the Modem.
64
65
it offers the follwing symbols:
66
<pre>
67 9 laforge
log_submit
68
pools
69
diag_vote_md_real_time
70
DiagSvc_Free
71
diag_dci_get_real_time_status_proc
72
diagpkt_subsys_get_delayed_rsp_id
73
diagpkt_subsys_alloc_v2
74
diag_read_mask_file_list
75
diagpkt_subsys_get_cmd_code
76
Diag_LSM_Event_DeInit
77
diag_wakelock_init
78
mask_file2
79
cleanup_mask
80
diag_register_dci_client
81
mask_file
82
msg_send_var
83
diagpkt_subsys_alloc_v2_delay
84
log_to_memory
85
diagpkt_alloc
86
db_thread_initialized
87
_init
88
stop_cond
89
diag_hdlc_toggle
90
diag_wakelock_acquire
91
parser_state
92
num_bytes_read
93
log_update_dci_mask
94
send_mask_modem
95
qsr4_db_file_fd
96
qsr4_db_write_buf_pool
97
event_update_mask
98
mask_sync_initialize
99
file_name_curr
100
msg_sprintf
101
mask_file_mdm2
102
event_report_payload
103
DiagSvc_Malloc_Init
104
diag_release_dci_client
105
update_sync_mask
106
diag_send_socket_data
107
diag_register_dci_stream_proc
108
DiagSvc_Malloc
109
buffer_init
110
msg_mask_tbl_size
111
curr_write_idx
112
diag_logger_flush
113
pool0_buffers
114
log_set_length
115
hdlc_disabled
116
fd_qsr4_xml
117
qsr4_xml_file_name
118
diagpkt_LSM_process_request
119
diag_get_real_time_status
120
Diag_LSM_Pkt_DeInit
121
flush_buffer
122
diag_callback_send_data
123
dci_cumulative_event_mask
124
dci_transaction_id
125
diag_get_health_stats_proc
126
stop_mutex
127
diag_get_health_stats
128
log_free
129
mask_file_mdm
130
diagpkt_subsys_reset_delayed_rsp_id
131
diag_logger_init
132
dummy_handler
133
diag_send_data
134
diag_kill_qshrink4_threads
135
ts_get_lohi
136
diagpkt_subsys_set_rsp_cnt
137
diag_notify_parser_thread
138
diag_disable_all_logs
139
diagpkt_commit
140
proc_type
141
diag_log_stream_config
142
log_status
143
msg_send
144
WriteToDisk
145
Diag_LSM_Log_DeInit
146
fd_dev
147
diag_dci_get_real_time_status
148
qsr4_db_cmd_req_buf
149
diagpkt_subsys_alloc
150
get_sync_mask
151
diag_get_dci_support_list_proc
152
diag_get_real_time_status_proc
153
qsr4_read_db_mutex
154
dir_name
155
diag_set_socket_fd
156
diag_switch_logging_proc
157
diagpkt_get_cmd_code
158
diagpkt_subsys_get_status
159
in_read
160
Diag_LSM_Event_Init
161
diag_dci_error_type
162
diag_disable_all_events
163
pid_file
164
qsr4_db_parser_thread_hdl
165
num_dci_proc
166
in_wait_for_peripheral_status
167
write_in_progress
168
Diag_LSM_Pkt_Init
169
max_file_size
170
ts_get
171
diag_get_event_status
172
log_set_timestamp
173
curr_read
174
diag_register_dci_signal_data
175
diagpkt_shorten
176
curr_read_idx
177
pool1_buffers
178
lookup_pkt_rsp_transaction
179
diag_disable_console
180
max_file_num
181
diag_send_dci_async_req
182
log_get_length
183
diagpkt_set_cmd_code
184
diagpkt_subsys_set_status
185
diag_peripheral_buffering_drain_immediate
186
event_mask
187
log_commit
188
min_file_size
189
gdwClientID
190
msg_send_ts
191
read_thread_hdl
192
valid_token
193
add_guid_to_qshrink4_header
194
msg_mask
195
file_list_size
196
log_shorten
197
diagpkt_free
198
fd_socket
199
flush_log
200
create_diag_qshrink4_db_parser_thread
201
diag_read_mask_file
202
diag_deregister_dci_signal_data
203
num_dci_clients_event
204
proc_name
205
diag_lsm_dci_deinit
206
diag_wakelock_release
207
read_buffer
208
diagpkt_subsys_get_id
209
peripheral_name
210
Diag_LSM_Init
211
diag_configure_peripheral_buffering_tx_mode
212
curr_write
213
diag_callback_send_data_hdlc
214
qsr_msg_send_1
215
qsr_msg_send_2
216
db_write_thread_hdl
217
Diag_LSM_Msg_Init
218
qsr_msg_send_3
219
token_list
220
diag_has_remote_device
221
diag_register_remote_callback
222
in_write
223
file_list
224
process_incoming_data
225
delete_log
226
log_to_device
227
logging_mode
228
log_set_code
229
diagpkt_delay_commit
230
flush_in_progress
231
diag_send_to_output
232
diag_get_max_channels
233
Diag_LSM_Log_Init
234
file_name_del
235
uart_logging_proc
236
DiagSvc_Malloc_Exit
237
output_dir
238
diag_event_stream_config
239
Diag_LSM_DeInit
240
diagpkt_tbl_reg
241
diag_dci_vote_real_time
242
kill_thread
243
count_written_bytes_1
244
qsr_msg_send
245
event_report
246
diag_fd
247
event_update_dci_mask
248
diag_get_dci_support_list
249
log_update_mask
250
parse_data_for_qsr4_db_file_op_rsp
251
file_list_index
252
rename_file_names
253
diag_register_callback
254
diag_lsm_dci_init
255
diag_vote_md_real_time_proc
256
msg_send_1
257
msg_send_2
258
msg_send_3
259
diag_is_wakelock_init
260
disk_write_hdl
261
diag_register_socket_cb
262
msg_update_mask
263
diag_set_peripheral_mask
264
log_alloc
265
dci_client_tbl
266
do_mask_sync
267
write_qshrink_header
268
fd_uart
269
qsr_msg_send_var
270
periph_info
271
diag_logger_exit
272
send_empty_mask
273
gnDiag_LSM_Event_Initialized
274
diagpkt_err_rsp
275
diag_logger_write
276
diag_get_log_status
277
qsr4_read_db_cond
278
rename_dir_name
279
diag_wakelock_destroy
280
diag_register_dci_stream
281
log_get_code
282
msg_mask_tbl
283
Diag_LSM_Msg_DeInit
284
to_integer
285
_fini
286
diag_get_peripheral_name_from_mask
287
count_written_bytes
288
diag_switch_logging
289
fd_md
290 4 laforge
</pre>
291 5 laforge
292 10 laforge
h3. Initialization
293
294
|_.Function|_.Purpose|
295
|Diag_LSM_Init()|Registering with Diag which gives the client a handle to the Diag. Called once per process|
296
297 5 laforge
h3. Logging Service API
298
299
This is about sending log messages via the Diag interface.
300
301
|_.Function|_.Purpose|
302
|log_alloc(u16 code, len)|Allocate a buffer + fill header|
303
|log_shorten(ptr, len)|Shorten the length of a previously allocated buffer|
304
|log_commit(ptr)|Send the log to diag|
305
|log_free(ptr)|Free a buffer previously allocated with log_alloc()|
306
|log_submit(ptr)|Convenience wrapper around log_alloc()/memcpy()/log_commit()|
307
308 7 laforge
On the [[EC25]], it seems only the following Linux programs use the avove API to generate logs via Diag:
309
* @/usr/bin/cnss_diag@
310
* @/usr/bin/ftmdaemon@
311
* @/usr/bin/mbimd@
312
* @/usr/bin/test_diag@
313
314 5 laforge
h3. Diag Consumer Interface
315
316 1 laforge
This seems to be about implementing a program that consumes Diag events. You can register to certain events/masks and then receive the related information in call-backs.
317 8 laforge
318
|_.Function|_.Description|
319
|diag_lsm_dci_init()|Initialize DCI subsystem of libdiag|
320 11 laforge
|diag_register_dci_client()|Register a DCI client, issues DIAG_IOCTL_DCI_REG to /dev/diag|
321
|diag_get_dci_support_list()|Get list of peripherals supported, issues DIAG_IOCTL_DCI_SUPPORT to /dev/diag|
322
|diag_register_dci_stream()|Register call-backs for events and logs, writes to /dev/diag|
323
|diag_event_stream_config()|Set up event streaming to the client, writes to /dev/diag|
324
|diag_log_stream_config()|Specify array of requested log codes, writes to /dev/diag|
325
|diag_get_health_stats()|Get statistics about missed/succeeded logs and events, issues DIAG_IOCTL_DCI_HEALTH_STATS to /dev/diag|
326 8 laforge
|diag_register_dci_signal_data()|Request OS signal when DCI data is received|
327 13 laforge
328 14 laforge
h2. How to configure/enable logging
329 13 laforge
330
An external DIAG receiver (e.g. on the host PC) can configure which particular log messages he wants to receive and which not.
331
332
For the Linux programs using the libdiag.so logging service API, this means that every time an external DIAG log receiver updates the DIAG mask, that mask is passed into every program using libdiag, so they can update their log masks.  This is done by reading on the @/dev/diag@ device and calling into  @process_diag_payload()@ which in turn calls @log_update_mask()@ pr @msg_update_mask()@ which updates the @log_mask@ array.
333
334
When a given log line is created, exactly that @log_mask@ or @read_mask@ array is consulted to check if the given subsystem is enabled or not.
Add picture from clipboard (Maximum size: 48.8 MB)