📄 xsupgui_request6.c
字号:
if ((device == NULL) || (ssids == NULL)) return IPC_ERROR_INVALID_PARAMETERS;
(*ssids) = NULL;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto finish_enum_ssids;
}
n = xmlNewChild(n, NULL, "Enum_Known_SSIDs", NULL);
if (n == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish_enum_ssids;
}
xsupgui_xml_common_convert_amp(device, &temp);
if (xmlNewChild(n, NULL, "Interface", temp) == NULL)
{
done = IPC_ERROR_CANT_CREATE_INT_NODE;
free(temp);
goto finish_enum_ssids;
}
free(temp);
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish_enum_ssids;
}
// Otherwise, parse it and see if we got what we wanted.
// Check if we got errors.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
done = err;
goto finish_enum_ssids;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto finish_enum_ssids;
}
// If we get here, then we know that the document passed the
// validation tests imposed. So, we need to see if we got the result
// we wanted.
n = xsupgui_request_find_node(n->children, "Known_SSID_List");
if (n == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto finish_enum_ssids;
}
t = xsupgui_request_find_node(n->children, "SSIDs_Count");
if (t == NULL)
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_ssids;
}
content = xmlNodeGetContent(t);
if (content == NULL)
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_ssids;
}
#ifdef REQUEST_DEBUG
printf("%s SSID(s) found!\n", content);
#endif
if (content != NULL)
{
numssids = atoi(content);
if (content != NULL) free(content);
}
else
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_ssids;
}
// Allocate memory for our return structure.
ssidarray = malloc(sizeof(ssid_info_enum)*(numssids+1));
if (ssidarray == NULL)
{
#ifdef REQUEST_DEBUG
printf("Couldn't allocate memory to return SSID data!\n");
#endif
done = IPC_ERROR_CANT_ALLOCATE_MEMORY;
goto finish_enum_ssids;
}
// Clear the memory.
memset(ssidarray, 0x00, (sizeof(ssid_info_enum)*(numssids+1)));
n = n->children;
for (i=0; i <numssids; i++)
{
n = xsupgui_request_find_node(n, "SSID");
if (n == NULL)
{
if (ssidarray != NULL) free(ssidarray);
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_ssids;
}
t = xsupgui_request_find_node(n->children, "SSID_Name");
if (t == NULL)
{
if (ssidarray != NULL) free(ssidarray);
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_ssids;
}
ssidarray[i].ssidname = xmlNodeGetContent(t);
t = xsupgui_request_find_node(n->children, "SSID_Abilities");
if (t == NULL)
{
if (ssidarray != NULL) free(ssidarray);
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish_enum_ssids;
}
content = xmlNodeGetContent(t);
ssidarray[i].abil = atoi(content);
xmlFree(content);
n = n->next;
}
(*ssids) = ssidarray;
done = REQUEST_SUCCESS;
finish_enum_ssids:
if (doc) xmlFreeDoc(doc);
if (retdoc) xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Free the memory used by the SSID enum structure.
*
* @param[in] ssids The array of SSID enum data that we want to free
* the memory from.
*
* \retval REQUEST_SUCCESS on success
* \retval REQUEST_FAILURE on failure
**/
int xsupgui_request_free_ssid_enum(ssid_info_enum **ssids)
{
int i = 0;
ssid_info_enum *ssid;
ssid = (*ssids);
if (!ssid)
return REQUEST_SUCCESS;
while (ssid[i].ssidname != NULL)
{
free(ssid[i].ssidname);
i++;
}
free((*ssids));
return REQUEST_SUCCESS;
}
/**
* \brief Request that the supplicant start a new scan.
*
* \warning If this request is for an active scan, the user
* will be disconnected from the current wireless
* network. However, a passive scan may not be possible
* depending on the platform in use. (And attempting
* to do a passive scan may not return an error, depending
* on the OS.)
*
* @param[in] devname The OS specific device name that we want to start the
* scan on.
* @param[in] passive A TRUE or FALSE value indicating if we would like to
* initiate a passive scan. If this is set to TRUE, and
* there is a way to trap an error from the OS that
* indicates that it can't do a passive scan, an error will
* be returned. Right now, Linux doesn't seem able to trap
* an error, and will initiate an active scan.
*
* \retval >299 the request to the supplicant failed, if passive == TRUE, then you
* may want to consider calling this function again with passive == FALSE.
* \retval REQUEST_TIMEOUT the request timed out
* \retval REQUEST_SUCCESS the request succeeded.
**/
int xsupgui_request_wireless_scan(char *devname, uint8_t passive)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
char tempstatic[100];
int done = REQUEST_SUCCESS;
int err = 0;
char *temp = NULL;
if (devname == NULL) return IPC_ERROR_INVALID_PARAMETERS;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto finish_wireless_scan;
}
t = xmlNewChild(n, NULL, "Wireless_Scan", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish_wireless_scan;
}
xsupgui_xml_common_convert_amp(devname, &temp);
if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
{
done = IPC_ERROR_CANT_CREATE_INT_NODE;
free(temp);
goto finish_wireless_scan;
}
free(temp);
sprintf((char *)&tempstatic, "%d", passive);
if (xmlNewChild(t, NULL, "Passive", tempstatic) == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish_wireless_scan;
}
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish_wireless_scan;
}
// Check if we got errors.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
done = err;
goto finish_wireless_scan;
}
done = xsupgui_request_is_ack(retdoc);
finish_wireless_scan:
xmlFreeDoc(doc);
xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Request that the supplicant send us version information.
*
* @param[out] verstr The version string for the running supplicant.
* @param[out] errcode An error code that indicates what went wrong.
*
* \retval >299 the request to the supplicant failed
* \retval REQUEST_TIMEOUT the request timed out
* \retval REQUEST_SUCCESS the request succeeded
**/
int xsupgui_request_version_string(char **verstr)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL;
int done = REQUEST_SUCCESS;
int err = 0;
FILE *fh;
if (verstr == NULL) return IPC_ERROR_INVALID_PARAMETERS;
(*verstr) = NULL;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto finish;
}
t = xmlNewChild(n, NULL, "Get_Version_String", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish;
}
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish;
}
// Otherwise, parse it and see if we got what we wanted.
// Check if we got errors.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
done = err;
goto finish;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto finish;
}
// If we get here, then we know that the document passed the
// validation tests imposed. So, we need to see if we got the result
// we wanted.
n = xsupgui_request_find_node(n->children, "Version_String");
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESPONSE;
goto finish;
}
(*verstr) = xmlNodeGetContent(n);
if (((*verstr) == NULL) || (strlen((*verstr)) == 0))
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
}
done = REQUEST_SUCCESS;
finish:
xmlFreeDoc(doc);
xmlFreeDoc(retdoc);
return done;
}
/**
* \brief Return an array of root CA certificates.
*
* @param[in,out] casa An array of root CA certificates. The final element in the
* array will be NULL.
*
* \retval REQUEST_FAILURE the request to the supplicant failed
* \retval REQUEST_TIMEOUT the request timed out
* \retval REQUEST_SUCCESS the request succeeded
**/
int xsupgui_request_enum_root_ca_certs(cert_enum **casa)
{
xmlDocPtr doc = NULL;
xmlDocPtr retdoc = NULL;
xmlNodePtr n = NULL, t = NULL, b = NULL;
int done = REQUEST_SUCCESS;
int err = 0;
int i = 0;
int numcerts = 0;
char *value = NULL;
cert_enum *cas = NULL;
if (casa == NULL) return IPC_ERROR_INVALID_PARAMETERS;
(*casa) = NULL;
doc = xsupgui_xml_common_build_msg();
if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;
n = xmlDocGetRootElement(doc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
goto finish;
}
t = xmlNewChild(n, NULL, "Enum_Root_CA_Certs", NULL);
if (t == NULL)
{
done = IPC_ERROR_CANT_CREATE_REQUEST;
goto finish;
}
err = xsupgui_request_send(doc, &retdoc);
if (err != REQUEST_SUCCESS)
{
done = err;
goto finish;
}
// Otherwise, parse it and see if we got what we wanted.
// Check if we got errors.
err = xsupgui_request_check_exceptions(retdoc);
if (err != 0)
{
done = err;
goto finish;
}
n = xmlDocGetRootElement(retdoc);
if (n == NULL)
{
done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
goto finish;
}
n = xsupgui_request_find_node(n->children, "Root_CA_Certs_Enum");
if (n == NULL)
{
done = IPC_ERROR_BAD_RESPONSE;
goto finish;
}
// If we get here, then we know that the document passed the
// validation tests imposed. So, we need to see if we got the result
// we wanted.
n = xsupgui_request_find_node(n->children, "Number_Of_Certs");
if (n == NULL)
{
done = IPC_ERROR_BAD_RESPONSE_DATA;
goto finish;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -