1 /*
2 * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file lib_printf.c
9 *
10 * This file contains library-specific printf functions
11 * used by WiFi libraries in the `lib` directory.
12 * These function are used to catch any output which gets printed
13 * by libraries, and redirect it to ESP_LOG macros.
14 *
15 * Eventually WiFi libraries will use ESP_LOG functions internally
16 * and these definitions will be removed.
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "esp_log.h"
22 #include "esp_attr.h"
23
24 #define VPRINTF_STACK_BUFFER_SIZE 80
25
lib_printf(const char * tag,const char * format,va_list arg)26 static int lib_printf(const char* tag, const char* format, va_list arg)
27 {
28 char temp[VPRINTF_STACK_BUFFER_SIZE];
29 int len = vsnprintf(temp, sizeof(temp) - 1, format, arg);
30 temp[sizeof(temp) - 1] = 0;
31 int i;
32 for (i = len - 1; i >= 0; --i) {
33 if (temp[i] != '\n' && temp[i] != '\r' && temp[i] != ' ') {
34 break;
35 }
36 temp[i] = 0;
37 }
38 if (i > 0) {
39 ESP_LOGI(tag, "%s", temp);
40 }
41 va_end(arg);
42 return len;
43 }
44
phy_printf(const char * format,...)45 int phy_printf(const char* format, ...)
46 {
47 va_list arg;
48 va_start(arg, format);
49 int res = lib_printf("phy", format, arg);
50 va_end(arg);
51 return res;
52 }
53
54
rtc_printf(const char * format,...)55 int rtc_printf(const char* format, ...)
56 {
57 // librtc.a printf temporary disabled due to UART baud rate switching bug.
58 return 0;
59 }
60
wpa_printf(const char * format,...)61 int wpa_printf(const char* format, ...)
62 {
63 va_list arg;
64 va_start(arg, format);
65 int res = lib_printf("wpa", format, arg);
66 va_end(arg);
67 return res;
68 }
69
wpa2_printf(const char * format,...)70 int wpa2_printf(const char* format, ...)
71 {
72 va_list arg;
73 va_start(arg, format);
74 int res = lib_printf("wpa2", format, arg);
75 va_end(arg);
76 return res;
77 }
78
wps_printf(const char * format,...)79 int wps_printf(const char* format, ...)
80 {
81 va_list arg;
82 va_start(arg, format);
83 int res = lib_printf("wps", format, arg);
84 va_end(arg);
85 return res;
86 }
87
pp_printf(const char * format,...)88 int pp_printf(const char* format, ...)
89 {
90 va_list arg;
91 va_start(arg, format);
92 int res = lib_printf("pp", format, arg);
93 va_end(arg);
94 return res;
95 }
96
sc_printf(const char * format,...)97 int sc_printf(const char* format, ...)
98 {
99 va_list arg;
100 va_start(arg, format);
101 int res = lib_printf("smartconfig", format, arg);
102 va_end(arg);
103 return res;
104 }
105
core_printf(const char * format,...)106 int core_printf(const char* format, ...)
107 {
108 va_list arg;
109 va_start(arg, format);
110 int res = lib_printf("core", format, arg);
111 va_end(arg);
112 return res;
113 }
114
net80211_printf(const char * format,...)115 int net80211_printf(const char* format, ...)
116 {
117 va_list arg;
118 va_start(arg, format);
119 int res = lib_printf("net80211", format, arg);
120 va_end(arg);
121 return res;
122 }
123
coexist_printf(const char * format,...)124 int coexist_printf(const char* format, ...)
125 {
126 va_list arg;
127 va_start(arg, format);
128 int res = lib_printf("coexist", format, arg);
129 va_end(arg);
130 return res;
131 }
132
wapi_printf(const char * format,...)133 int wapi_printf(const char* format, ...)
134 {
135 va_list arg;
136 va_start(arg, format);
137 int res = lib_printf("wapi", format, arg);
138 va_end(arg);
139 return res;
140 }
141
mesh_printf(const char * format,...)142 int mesh_printf(const char* format, ...)
143 {
144 va_list arg;
145 va_start(arg, format);
146 int res = lib_printf("mesh", format, arg);
147 va_end(arg);
148 return res;
149 }
150