From a802c7f40d14a49f1960290d1590ea7fd5e4d36c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 4 Jan 2011 18:25:14 -0600 Subject: [PATCH] wimax: work around wide-char stupidity in Intel WiMAX SDK The SDK internally use wchar_t for NSP names even though the names are actually UTF-8 (since the driver uses UTF-8/ASCII). So work around that by using the full network name buffer in case the NSP name is an odd number of characters and thus widechar comparison functions like wcscmp() would fail when given ASCII. --- src/wimax/iwmxsdk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wimax/iwmxsdk.c b/src/wimax/iwmxsdk.c index 54ad84e8d..85ef709cf 100644 --- a/src/wimax/iwmxsdk.c +++ b/src/wimax/iwmxsdk.c @@ -661,6 +661,7 @@ int iwmx_sdk_connect(struct wmxsdk *wmxsdk, const char *nsp_name) char errstr[512]; UINT32 errstr_size = sizeof(errstr); WIMAX_API_DEVICE_STATUS dev_status; + char sdk_name[MAX_SIZE_OF_NSP_NAME]; g_mutex_lock(wmxsdk->connect_mutex); /* Guess what the current radio state is; if it is ON @@ -696,8 +697,15 @@ int iwmx_sdk_connect(struct wmxsdk *wmxsdk, const char *nsp_name) g_assert(1); } + /* The SDK treats the network name as wchar_t* while the contents are + * actually just UTF-8... WTF? Hand it a full buffer to work around + * boundary cases where the NSP name contains an odd # of characters. + */ + memset(sdk_name, 0, sizeof (sdk_name)); + memcpy(sdk_name, nsp_name, strlen (nsp_name)); + /* Ok, do the connection, wait for a callback */ - r = CmdConnectToNetwork(&wmxsdk->device_id, (void *) nsp_name, 0, 0); + r = CmdConnectToNetwork(&wmxsdk->device_id, &sdk_name[0], 0, 0); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot connect to network %s: %d (%s) - device is in state '%s'",