1 #include "../helper/locales.h"
9 # include <sys/types.h>
10 # include <sys/stat.h>
12 # define THREAD_RETURN void *
13 # define THREAD_RETURN_VAL NULL
15 # define HAVE_WIN32_THREADS
16 # define WIN32_LEAN_AND_MEAN
18 # define THREAD_RETURN DWORD
19 # define THREAD_RETURN_VAL 0
25 #include "../helper/formats.h"
26 #include "../helper/string.h"
28 #if defined(HAVE_WIN32_THREADS) || defined(HAVE_PTHREAD)
30 * Structure to hold information about connection for searching.
36 unsigned char Connection
[50];
40 * Structure to hold device information for phone searching.
46 unsigned char Device
[50];
48 * List of connections to try
50 OneConnectionInfo Connections
[5];
53 gboolean SearchOutput
;
56 * Like printf, but only when output from searching is enabled.
59 int SearchPrintf(const char *format
, ...)
68 ret
= vprintf(format
, ap
);
74 void SearchPrintPhoneInfo(GSM_StateMachine
* sm
)
77 char buffer
[GSM_MAX_INFO_LENGTH
];
79 /* Try to get phone manufacturer */
80 error
= GSM_GetManufacturer(sm
, buffer
);
82 /* Bail out if we failed */
83 if (error
!= ERR_NONE
) {
84 SearchPrintf("\t%s\n", GSM_ErrorString(error
));
88 /* Print basic information */
89 printf("\t" LISTFORMAT
"%s\n", _("Manufacturer"), buffer
);
91 /* Try to get phone model */
92 error
= GSM_GetModel(sm
, buffer
);
94 /* Bail out if we failed */
95 if (error
!= ERR_NONE
) {
96 SearchPrintf("\t%s\n", GSM_ErrorString(error
));
100 /* Print model information */
101 printf("\t" LISTFORMAT
"%s (%s)\n", _("Model"),
102 GSM_GetModelInfo(sm
)->model
, buffer
);
105 THREAD_RETURN
SearchPhoneThread(void * arg
)
108 OneDeviceInfo
*Info
= arg
;
110 GSM_StateMachine
*search_gsm
;
112 GSM_Config
*globalcfg
;
114 /* Iterate over all connections */
115 for (j
= 0; strlen(Info
->Connections
[j
].Connection
) != 0; j
++) {
117 /* Allocate state machine */
118 search_gsm
= GSM_AllocStateMachine();
119 if (search_gsm
== NULL
)
120 return THREAD_RETURN_VAL
;
122 /* Get configuration pointers */
123 smcfg
= GSM_GetConfig(search_gsm
, 0);
124 globalcfg
= GSM_GetConfig(gsm
, 0);
126 /* We share some configuration with global one */
127 smcfg
->UseGlobalDebugFile
= globalcfg
->UseGlobalDebugFile
;
128 smcfg
->DebugFile
= strdup(globalcfg
->DebugFile
);
129 strcpy(smcfg
->DebugLevel
, globalcfg
->DebugLevel
);
131 /* Configure the tested state machine */
132 smcfg
->Device
= strdup(Info
->Device
);
133 smcfg
->Connection
= strdup(Info
->Connections
[j
].Connection
);
134 smcfg
->SyncTime
= FALSE
;
136 smcfg
->LockDevice
= FALSE
;
137 smcfg
->StartInfo
= FALSE
;
139 /* We have only one configured connection */
140 GSM_SetConfigNum(search_gsm
, 1);
143 error
= GSM_InitConnection(search_gsm
, 1);
145 printf(_("Connection \"%s\" on device \"%s\"\n"),
146 Info
->Connections
[j
].Connection
, Info
->Device
);
148 /* Did we succeed? Show info */
149 if (error
== ERR_NONE
) {
150 SearchPrintPhoneInfo(search_gsm
);
152 SearchPrintf("\t%s\n", GSM_ErrorString(error
));
155 if (error
!= ERR_DEVICEOPENERROR
) {
156 GSM_TerminateConnection(search_gsm
);
159 if (error
== ERR_DEVICEOPENERROR
)
162 /* Free allocated buffer */
163 GSM_FreeStateMachine(search_gsm
);
165 return THREAD_RETURN_VAL
;
169 pthread_t Threads
[100];
174 OneDeviceInfo SearchDevices
[60];
176 void MakeSearchThread(int i
)
180 (&Threads
[i
], NULL
, SearchPhoneThread
,
181 &SearchDevices
[i
]) != 0) {
182 fprintf(stderr
, "%s", _("Error creating thread\n"));
185 Threads
[i
] = CreateThread((LPSECURITY_ATTRIBUTES
) NULL
, 0,
186 (LPTHREAD_START_ROUTINE
) SearchPhoneThread
,
187 &SearchDevices
[i
], 0, NULL
);
188 if (Threads
[i
] == NULL
) {
189 fprintf(stderr
, "%s", _("Error creating thread\n"));
194 void SearchPhone(int argc
, char *argv
[])
203 SearchOutput
= FALSE
;
204 if (argc
== 3 && strcasecmp(argv
[2], "-debug") == 0)
207 #ifdef HAVE_WIN32_THREADS
208 SearchDevices
[dev
].Device
[0] = 0;
209 sprintf(SearchDevices
[dev
].Connections
[0].Connection
, "irdaphonet");
210 sprintf(SearchDevices
[dev
].Connections
[1].Connection
, "irdaat");
211 SearchDevices
[dev
].Connections
[2].Connection
[0] = 0;
213 for (i
= 0; i
< 20; i
++) {
214 sprintf(SearchDevices
[dev
].Device
, "com%i:", i
+ 1);
215 sprintf(SearchDevices
[dev
].Connections
[0].Connection
,
217 sprintf(SearchDevices
[dev
].Connections
[1].Connection
, "fbus");
218 sprintf(SearchDevices
[dev
].Connections
[2].Connection
,
220 sprintf(SearchDevices
[dev
].Connections
[3].Connection
, "mbus");
221 SearchDevices
[dev
].Connections
[4].Connection
[0] = 0;
225 for (i
= 0; i
< 6; i
++) {
226 sprintf(SearchDevices
[dev
].Device
, "/dev/ircomm%i", i
);
227 fd
= open(SearchDevices
[dev
].Device
, O_RDWR
);
228 if (fd
< 0) continue;
230 sprintf(SearchDevices
[dev
].Connections
[0].Connection
,
232 sprintf(SearchDevices
[dev
].Connections
[1].Connection
,
234 SearchDevices
[dev
].Connections
[2].Connection
[0] = 0;
237 for (i
= 0; i
< 10; i
++) {
238 sprintf(SearchDevices
[dev
].Device
, "/dev/ttyS%i", i
);
239 fd
= open(SearchDevices
[dev
].Device
, O_RDWR
);
240 if (fd
< 0) continue;
242 sprintf(SearchDevices
[dev
].Connections
[0].Connection
,
244 sprintf(SearchDevices
[dev
].Connections
[1].Connection
, "fbus");
245 sprintf(SearchDevices
[dev
].Connections
[2].Connection
,
247 sprintf(SearchDevices
[dev
].Connections
[3].Connection
, "mbus");
248 SearchDevices
[dev
].Connections
[4].Connection
[0] = 0;
251 for (i
= 0; i
< 8; i
++) {
252 sprintf(SearchDevices
[dev
].Device
, "/dev/ttyD00%i", i
);
253 fd
= open(SearchDevices
[dev
].Device
, O_RDWR
);
254 if (fd
< 0) continue;
256 sprintf(SearchDevices
[dev
].Connections
[0].Connection
,
258 sprintf(SearchDevices
[dev
].Connections
[1].Connection
, "fbus");
259 sprintf(SearchDevices
[dev
].Connections
[2].Connection
,
261 sprintf(SearchDevices
[dev
].Connections
[3].Connection
, "mbus");
262 SearchDevices
[dev
].Connections
[4].Connection
[0] = 0;
265 for (i
= 0; i
< 4; i
++) {
266 sprintf(SearchDevices
[dev
].Device
, "/dev/usb/tts/%i", i
);
267 fd
= open(SearchDevices
[dev
].Device
, O_RDWR
);
268 if (fd
< 0) continue;
270 sprintf(SearchDevices
[dev
].Connections
[0].Connection
,
272 sprintf(SearchDevices
[dev
].Connections
[1].Connection
, "fbus");
273 sprintf(SearchDevices
[dev
].Connections
[2].Connection
,
275 sprintf(SearchDevices
[dev
].Connections
[3].Connection
, "mbus");
276 SearchDevices
[dev
].Connections
[4].Connection
[0] = 0;
280 for (i
= 0; i
< dev
; i
++)
282 #ifdef HAVE_WIN32_THREADS
283 WaitForMultipleObjects(dev
, Threads
, TRUE
, INFINITE
);
285 for (i
= 0; i
< dev
; i
++)
286 pthread_join(Threads
[i
], &ret
);
289 #endif /*Support for threads */
291 /* How should editor hadle tabs in this file? Add editor commands here.
292 * vim: noexpandtab sw=8 ts=8 sts=8: