| Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* | 
 | 2 |  * Sigma Control API DUT (station/AP) | 
 | 3 |  * Copyright (c) 2010, Atheros Communications, Inc. | 
 | 4 |  * All Rights Reserved. | 
 | 5 |  * Licensed under the Clear BSD license. See README for more details. | 
 | 6 |  */ | 
 | 7 |  | 
 | 8 | #include "sigma_dut.h" | 
 | 9 | #include "wpa_helpers.h" | 
 | 10 |  | 
 | 11 |  | 
 | 12 | static int cmd_sta_atheros(struct sigma_dut *dut, struct sigma_conn *conn, | 
 | 13 | 			   struct sigma_cmd *cmd) | 
 | 14 | { | 
 | 15 | 	char buf[2048], *pos; | 
 | 16 | 	int i; | 
 | 17 | 	const char *intf, *c; | 
 | 18 | 	char resp[200]; | 
 | 19 |  | 
 | 20 | 	intf = get_param(cmd, "interface"); | 
 | 21 | 	c = get_param(cmd, "cmd"); | 
 | 22 | 	if (c == NULL) | 
 | 23 | 		return -1; | 
 | 24 |  | 
 | 25 | 	buf[0] = '\0'; | 
 | 26 | 	if (strncmp(c, "ctrl=", 5) == 0) { | 
 | 27 | 		size_t rlen; | 
 | 28 | 		c += 5; | 
 | 29 | 		if (wpa_command_resp(intf, c, buf, sizeof(buf)) < 0) | 
 | 30 | 			return -2; | 
 | 31 | 		rlen = strlen(buf); | 
 | 32 | 		if (rlen > 0 && buf[rlen - 1] == '\n') | 
 | 33 | 			buf[rlen - 1] = '\0'; | 
 | 34 | 	} else if (strncmp(c, "timeout=", 8) == 0) { | 
 | 35 | 		unsigned int timeout; | 
 | 36 | 		timeout = atoi(c + 8); | 
 | 37 | 		if (timeout == 0) | 
 | 38 | 			return -1; | 
 | 39 | 		dut->default_timeout = timeout; | 
 | 40 | 		sigma_dut_print(dut, DUT_MSG_INFO, "Set DUT default timeout " | 
 | 41 | 				"to %u seconds", dut->default_timeout); | 
 | 42 | 		snprintf(buf, sizeof(buf), "OK"); | 
 | 43 | 	} else | 
 | 44 | 		return -2; | 
 | 45 |  | 
 | 46 | 	i = snprintf(resp, sizeof(resp), "resp,"); | 
 | 47 | 	pos = buf; | 
 | 48 | 	while (*pos && i + 1 < (int) sizeof(resp)) { | 
 | 49 | 		char c = *pos++; | 
 | 50 | 		if (c == '\n' || c == '\r' || c == ',') | 
 | 51 | 			c = '^'; | 
 | 52 | 		resp[i++] = c; | 
 | 53 | 	} | 
 | 54 | 	resp[i] = '\0'; | 
 | 55 |  | 
 | 56 | 	send_resp(dut, conn, SIGMA_COMPLETE, resp); | 
 | 57 | 	return 0; | 
 | 58 | } | 
 | 59 |  | 
 | 60 |  | 
 | 61 | static int req_intf(struct sigma_cmd *cmd) | 
 | 62 | { | 
 | 63 | 	return get_param(cmd, "interface") == NULL ? -1 : 0; | 
 | 64 | } | 
 | 65 |  | 
 | 66 |  | 
 | 67 | void atheros_register_cmds(void) | 
 | 68 | { | 
 | 69 | 	sigma_dut_reg_cmd("sta_atheros", req_intf, cmd_sta_atheros); | 
 | 70 | } |