• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 /**
16  * @file lib_printf.c
17  *
18  * This file contains library-specific printf functions
19  * used by WiFi libraries in the `lib` directory.
20  * These function are used to catch any output which gets printed
21  * by libraries, and redirect it to ESP_LOG macros.
22  *
23  * Eventually WiFi libraries will use ESP_LOG functions internally
24  * and these definitions will be removed.
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include "esp_log.h"
30 #include "esp_attr.h"
31 
32 #define VPRINTF_STACK_BUFFER_SIZE 80
33 
lib_printf(const char * tag,const char * format,va_list arg)34 static int lib_printf(const char* tag, const char* format, va_list arg)
35 {
36     char temp[VPRINTF_STACK_BUFFER_SIZE];
37     int len = vsnprintf(temp, sizeof(temp) - 1, format, arg);
38     temp[sizeof(temp) - 1] = 0;
39     int i;
40     for (i = len - 1; i >= 0; --i) {
41         if (temp[i] != '\n' && temp[i] != '\r' && temp[i] != ' ') {
42             break;
43         }
44         temp[i] = 0;
45     }
46     if (i > 0) {
47         ESP_LOGI(tag, "%s", temp);
48     }
49     va_end(arg);
50     return len;
51 }
52 
phy_printf(const char * format,...)53 int phy_printf(const char* format, ...)
54 {
55     va_list arg;
56     va_start(arg, format);
57     int res = lib_printf("phy", format, arg);
58     va_end(arg);
59     return res;
60 }
61 
62 
rtc_printf(const char * format,...)63 int rtc_printf(const char* format, ...)
64 {
65     // librtc.a printf temporary disabled due to UART baud rate switching bug.
66     return 0;
67 }
68 
wpa_printf(const char * format,...)69 int wpa_printf(const char* format, ...)
70 {
71     va_list arg;
72     va_start(arg, format);
73     int res = lib_printf("wpa", format, arg);
74     va_end(arg);
75     return res;
76 }
77 
wpa2_printf(const char * format,...)78 int wpa2_printf(const char* format, ...)
79 {
80     va_list arg;
81     va_start(arg, format);
82     int res = lib_printf("wpa2", format, arg);
83     va_end(arg);
84     return res;
85 }
86 
wps_printf(const char * format,...)87 int wps_printf(const char* format, ...)
88 {
89     va_list arg;
90     va_start(arg, format);
91     int res = lib_printf("wps", format, arg);
92     va_end(arg);
93     return res;
94 }
95 
pp_printf(const char * format,...)96 int pp_printf(const char* format, ...)
97 {
98     va_list arg;
99     va_start(arg, format);
100     int res = lib_printf("pp", format, arg);
101     va_end(arg);
102     return res;
103 }
104 
sc_printf(const char * format,...)105 int sc_printf(const char* format, ...)
106 {
107     va_list arg;
108     va_start(arg, format);
109     int res = lib_printf("smartconfig", format, arg);
110     va_end(arg);
111     return res;
112 }
113 
core_printf(const char * format,...)114 int core_printf(const char* format, ...)
115 {
116     va_list arg;
117     va_start(arg, format);
118     int res = lib_printf("core", format, arg);
119     va_end(arg);
120     return res;
121 }
122 
net80211_printf(const char * format,...)123 int net80211_printf(const char* format, ...)
124 {
125     va_list arg;
126     va_start(arg, format);
127     int res = lib_printf("net80211", format, arg);
128     va_end(arg);
129     return res;
130 }
131 
coexist_printf(const char * format,...)132 int coexist_printf(const char* format, ...)
133 {
134     va_list arg;
135     va_start(arg, format);
136     int res = lib_printf("coexist", format, arg);
137     va_end(arg);
138     return res;
139 }
140 
wapi_printf(const char * format,...)141 int wapi_printf(const char* format, ...)
142 {
143     va_list arg;
144     va_start(arg, format);
145     int res = lib_printf("coexist", format, arg);
146     va_end(arg);
147     return res;
148 }
149 
mesh_printf(const char * format,...)150 int mesh_printf(const char* format, ...)
151 {
152     va_list arg;
153     va_start(arg, format);
154     int res = lib_printf("mesh", format, arg);
155     va_end(arg);
156     return res;
157 }
158