1 /*
2 * SPDX-FileCopyrightText: 2016-2023 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 va_list arg;
58 va_start(arg, format);
59 int res = lib_printf("rtc", format, arg);
60 va_end(arg);
61 return res;
62 }
63
wpa_printf(const char * format,...)64 int wpa_printf(const char* format, ...)
65 {
66 va_list arg;
67 va_start(arg, format);
68 int res = lib_printf("wpa", format, arg);
69 va_end(arg);
70 return res;
71 }
72
wpa2_printf(const char * format,...)73 int wpa2_printf(const char* format, ...)
74 {
75 va_list arg;
76 va_start(arg, format);
77 int res = lib_printf("wpa2", format, arg);
78 va_end(arg);
79 return res;
80 }
81
wps_printf(const char * format,...)82 int wps_printf(const char* format, ...)
83 {
84 va_list arg;
85 va_start(arg, format);
86 int res = lib_printf("wps", format, arg);
87 va_end(arg);
88 return res;
89 }
90
pp_printf(const char * format,...)91 int pp_printf(const char* format, ...)
92 {
93 va_list arg;
94 va_start(arg, format);
95 int res = lib_printf("pp", format, arg);
96 va_end(arg);
97 return res;
98 }
99
sc_printf(const char * format,...)100 int sc_printf(const char* format, ...)
101 {
102 va_list arg;
103 va_start(arg, format);
104 int res = lib_printf("smartconfig", format, arg);
105 va_end(arg);
106 return res;
107 }
108
core_printf(const char * format,...)109 int core_printf(const char* format, ...)
110 {
111 va_list arg;
112 va_start(arg, format);
113 int res = lib_printf("core", format, arg);
114 va_end(arg);
115 return res;
116 }
117
net80211_printf(const char * format,...)118 int net80211_printf(const char* format, ...)
119 {
120 va_list arg;
121 va_start(arg, format);
122 int res = lib_printf("net80211", format, arg);
123 va_end(arg);
124 return res;
125 }
126
coexist_printf(const char * format,...)127 int coexist_printf(const char* format, ...)
128 {
129 va_list arg;
130 va_start(arg, format);
131 int res = lib_printf("coexist", format, arg);
132 va_end(arg);
133 return res;
134 }
135
wapi_printf(const char * format,...)136 int wapi_printf(const char* format, ...)
137 {
138 va_list arg;
139 va_start(arg, format);
140 int res = lib_printf("wapi", format, arg);
141 va_end(arg);
142 return res;
143 }
144
mesh_printf(const char * format,...)145 int mesh_printf(const char* format, ...)
146 {
147 va_list arg;
148 va_start(arg, format);
149 int res = lib_printf("mesh", format, arg);
150 va_end(arg);
151 return res;
152 }
153