1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25
26
27static inline void mdm_readline(char *buf, int bufsiz)
28{
29 char c;
30 char *p;
31 int n;
32
33 n = 0;
34 p = buf;
35 for(;;) {
36 c = serial_getc();
37
38
39
40 switch(c) {
41 case '\r':
42 break;
43 case '\n':
44 *p = '\0';
45 return;
46
47 default:
48 if(n++ > bufsiz) {
49 *p = '\0';
50 return;
51 }
52 *p = c;
53 p++;
54 break;
55 }
56 }
57}
58
59extern void dbg(const char *fmt, ...);
60int mdm_init (void)
61{
62 char env_str[16];
63 char *init_str;
64 int i;
65 extern char console_buffer[];
66 extern void enable_putc(void);
67 extern int hwflow_onoff(int);
68
69 enable_putc();
70
71#ifdef CONFIG_HWFLOW
72 init_str = getenv("mdm_flow_control");
73 if (init_str && (strcmp(init_str, "rts/cts") == 0))
74 hwflow_onoff (1);
75 else
76 hwflow_onoff(-1);
77#endif
78
79 for (i = 1;;i++) {
80 sprintf(env_str, "mdm_init%d", i);
81 if ((init_str = getenv(env_str)) != NULL) {
82 serial_puts(init_str);
83 serial_puts("\n");
84 for(;;) {
85 mdm_readline(console_buffer, CONFIG_SYS_CBSIZE);
86 dbg("ini%d: [%s]", i, console_buffer);
87
88 if ((strcmp(console_buffer, "OK") == 0) ||
89 (strcmp(console_buffer, "ERROR") == 0)) {
90 dbg("ini%d: cmd done", i);
91 break;
92 } else
93 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
94 dbg("ini%d: connect", i);
95 return 0;
96 }
97 }
98 } else
99 break;
100
101 udelay(100000);
102 }
103
104 udelay(100000);
105
106
107 for(;i > 1;) {
108
109 mdm_readline(console_buffer, CONFIG_SYS_CBSIZE);
110 dbg("ini_f: [%s]", console_buffer);
111 if (strncmp(console_buffer, "CONNECT", 7) == 0) {
112 dbg("ini_f: connected");
113 return 0;
114 }
115 }
116
117 return 0;
118}
119