Esempio n. 1
0
void ICACHE_FLASH_ATTR send_ok_templated(struct espconn *conn, char *response) {
    send_resp(conn, "HTTP/1.1 200 OK\r\n\r\n");
    send_resp(conn, header_html);
    send_resp(conn, response);
    send_resp(conn, footer_html);
    espconn_disconnect(conn);
}
Esempio n. 2
0
static int cmd_sniffer_control_field_check(struct sigma_dut *dut,
					   struct sigma_conn *conn,
					   struct sigma_cmd *cmd)
{
	const char *filename = get_param(cmd, "filename");
	const char *framename = get_param(cmd, "framename");
	const char *srcmac = get_param(cmd, "srcmac");
	const char *wsc_state = get_param(cmd, "WSC_State");
	const char *pvb_bit = get_param(cmd, "pvb_bit");
	const char *moredata_bit = get_param(cmd, "MoreData_bit");
	const char *eosp_bit = get_param(cmd, "EOSP_bit");
	char buf[2000], *pos;
	FILE *f;

	if (filename == NULL || srcmac == NULL)
		return -1;

	if (strchr(filename, '/')) {
		send_resp(dut, conn, SIGMA_ERROR, "errorCode,Invalid filename");
		return 0;
	}

	if (!file_exists("sniffer-control-field-check.py")) {
		send_resp(dut, conn, SIGMA_ERROR, "errorCode,sniffer-control-field-check.py not found");
		return 0;
	}

	snprintf(buf, sizeof(buf),
		 "./sniffer-control-field-check.py FileName=Captures/%s SrcMac=%s%s%s%s%s%s%s%s%s%s%s",
		 filename, srcmac,
		 framename ? " FrameName=" : "", framename ? framename : "",
		 wsc_state ? " WSC_State=" : "", wsc_state ? wsc_state : "",
		 moredata_bit ? " MoreData_bit=" : "",
		 moredata_bit ? moredata_bit : "",
		 eosp_bit ? " EOSP_bit=" : "", eosp_bit ? eosp_bit : "",
		 pvb_bit ? " pvb_bit=" : "", pvb_bit ? pvb_bit : "");
	sigma_dut_print(dut, DUT_MSG_INFO, "Run: %s", buf);
	f = popen(buf, "r");
	if (f == NULL) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed to run sniffer helper");
		return 0;
	}

	if (!fgets(buf, sizeof(buf), f)) {
		pclose(f);
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed extract response from sniffer helper");
		return 0;
	}
	pos = strchr(buf, '\n');
	if (pos)
		*pos = '\0';

	pclose(f);

	send_resp(dut, conn, SIGMA_COMPLETE, buf);
	return 0;
}
Esempio n. 3
0
/* give the appropriate response to the SER client */
int srv_response(struct sip_msg* msg, rd_buf_t * rb, int hftype)
{
	int auth_hf_len=0, ret=0;
	char* auth_hf;

	switch(rb->ret_code)
	{
		case AAA_AUTHORIZED:
			return 1;
			
		case AAA_NOT_AUTHORIZED:
			send_resp(msg, 403, "Forbidden", NULL, 0);	
			return -1;

		case AAA_SRVERR:
			send_resp(msg, 500, "Internal Server Error", NULL, 0);	
			return -1;
				
		case AAA_CHALENGE:
		 	if(hftype==HDR_AUTHORIZATION) /* SIP server */
			{
				auth_hf_len = WWW_AUTH_CHALLENGE_LEN+rb->chall_len;
				auth_hf = (char*)ad_malloc(auth_hf_len*(sizeof(char)));
				memset(auth_hf, 0, auth_hf_len);
				memcpy(auth_hf,WWW_AUTH_CHALLENGE, WWW_AUTH_CHALLENGE_LEN);
				memcpy(auth_hf+WWW_AUTH_CHALLENGE_LEN, rb->chall,
					rb->chall_len);
		
				ret = send_resp(msg, 401, MESSAGE_401, auth_hf, auth_hf_len);

			}
			else	/* Proxy Server */
			{
				auth_hf_len = PROXY_AUTH_CHALLENGE_LEN+rb->chall_len;
				auth_hf = (char*)ad_malloc(auth_hf_len*(sizeof(char)));
				memset(auth_hf, 0, auth_hf_len);
				memcpy(auth_hf, PROXY_AUTH_CHALLENGE, PROXY_AUTH_CHALLENGE_LEN);
				memcpy(auth_hf + PROXY_AUTH_CHALLENGE_LEN, rb->chall, 
						rb->chall_len);
				ret = send_resp(msg, 407, MESSAGE_407, auth_hf, auth_hf_len);
			}

			if (auth_hf) pkg_free(auth_hf);
	
			if (ret == -1) 
			{
				LOG(L_ERR, M_NAME":srv_response():Error while sending challenge "
					"to the client of SER\n");
				return -1;
			}
			return -1;
	}
	
	// never reach this 
	return -1;		
}
Esempio n. 4
0
static int cmd_sniffer_control_filter_capture(struct sigma_dut *dut,
					      struct sigma_conn *conn,
					      struct sigma_cmd *cmd)
{
	const char *infile = get_param(cmd, "InFile");
	const char *outfile = get_param(cmd, "OutFile");
	const char *srcmac = get_param(cmd, "SrcMac");
	const char *framename = get_param(cmd, "FrameName");
	const char *nframes = get_param(cmd, "Nframes");
	const char *hasfield = get_param(cmd, "HasField");
	const char *datalen = get_param(cmd, "Datalen");
	char buf[500], *pos;
	FILE *f;

	if (infile == NULL || outfile == NULL || srcmac == NULL ||
	    nframes == NULL)
		return -1;

	if (strchr(infile, '/') || strchr(outfile, '/'))
		return -1;

	if (!file_exists("sniffer-control-filter-capture.py")) {
		send_resp(dut, conn, SIGMA_ERROR, "errorCode,sniffer-control-filter-capture.py not found");
		return 0;
	}

	snprintf(buf, sizeof(buf),
		 "./sniffer-control-filter-capture.py InFile=Captures/%s OutFile=Captures/%s SrcMac=%s%s%s Nframes=%s%s%s%s%s",
		 infile, outfile, srcmac,
		 framename ? " FrameName=" : "", framename ? framename : "",
		 nframes,
		 hasfield ? " HasField=" : "", hasfield ? hasfield : "",
		 datalen ? " Datalen=" : "", datalen ? datalen : "");
	sigma_dut_print(dut, DUT_MSG_INFO, "Run: %s", buf);
	f = popen(buf, "r");
	if (f == NULL) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed to run sniffer helper");
		return 0;
	}

	if (!fgets(buf, sizeof(buf), f)) {
		pclose(f);
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed extract response from sniffer helper");
		return 0;
	}
	pos = strchr(buf, '\n');
	if (pos)
		*pos = '\0';

	pclose(f);

	send_resp(dut, conn, SIGMA_COMPLETE, buf);
	return 0;
}
Esempio n. 5
0
/* give the appropriate response to the SER client */
int srv_response(struct sip_msg* msg, rd_buf_t * rb, int hftype)
{
	int auth_hf_len=0, ret=0;
	char* auth_hf;

	switch(rb->ret_code)
	{
		case AAA_AUTHORIZED:
			return 1;

		case AAA_NOT_AUTHORIZED:
			send_resp(msg, 403, &dia_403_err, NULL, 0);
			return -1;

		case AAA_SRVERR:
			send_resp(msg, 500, &dia_500_err, NULL, 0);
			return -1;

		case AAA_CHALENGE:
		 	if(hftype==HDR_AUTHORIZATION_T) /* SIP server */
			{
				auth_hf_len = WWW_AUTH_CHALLENGE_LEN+rb->chall_len;
				auth_hf = (char*)ad_malloc(auth_hf_len*(sizeof(char)));
				memset(auth_hf, 0, auth_hf_len);
				memcpy(auth_hf,WWW_AUTH_CHALLENGE, WWW_AUTH_CHALLENGE_LEN);
				memcpy(auth_hf+WWW_AUTH_CHALLENGE_LEN, rb->chall,
					rb->chall_len);

				ret = send_resp(msg, 401, &dia_401_err, auth_hf, auth_hf_len);

			}
			else	/* Proxy Server */
			{
				auth_hf_len = PROXY_AUTH_CHALLENGE_LEN+rb->chall_len;
				auth_hf = (char*)ad_malloc(auth_hf_len*(sizeof(char)));
				memset(auth_hf, 0, auth_hf_len);
				memcpy(auth_hf, PROXY_AUTH_CHALLENGE, PROXY_AUTH_CHALLENGE_LEN);
				memcpy(auth_hf + PROXY_AUTH_CHALLENGE_LEN, rb->chall,
						rb->chall_len);
				ret = send_resp(msg, 407, &dia_407_err, auth_hf, auth_hf_len);
			}

			if (auth_hf) pkg_free(auth_hf);

			if (ret == -1)
			{
				LM_ERR("failed to send challenge to the client of SER\n");
				return -1;
			}
			return -1;
	}

	// never reach this
	return -1;
}
Esempio n. 6
0
/*
 * Create and send a challenge
 */
static inline int challenge(struct sip_msg* _msg, str* _realm, int _qop, 
			    int _code, char* _message, char* _challenge_msg)
{
	int auth_hf_len;
	struct hdr_field* h;
	auth_body_t* cred = 0;
	char *auth_hf;
	int ret, hftype = 0; /* Makes gcc happy */
	struct sip_uri uri;

	switch(_code) {
	case 401: 
		get_authorized_cred(_msg->authorization, &h); 
		hftype = HDR_AUTHORIZATION;
		break;
	case 407: 
		get_authorized_cred(_msg->proxy_auth, &h);
		hftype = HDR_PROXYAUTH;
		break;
	}

	if (h) cred = (auth_body_t*)(h->parsed);

	if (_realm->len == 0) {
		if (get_realm(_msg, hftype, &uri) < 0) {
			LOG(L_ERR, "challenge(): Error while extracting URI\n");
			if (send_resp(_msg, 400, MESSAGE_400, 0, 0) == -1) {
				LOG(L_ERR, "challenge(): Error while sending response\n");
				return -1;
			}
			return 0;
		}

		_realm = &uri.host;
		strip_realm(_realm);
	}

	auth_hf = build_auth_hf(0, (cred ? cred->stale : 0), _realm, &auth_hf_len, _qop, _challenge_msg);
	if (!auth_hf) {
		LOG(L_ERR, "ERROR: challenge: no mem w/cred\n");
		return -1;
	}
	
	ret = send_resp(_msg, _code, _message, auth_hf, auth_hf_len);
	if (auth_hf) pkg_free(auth_hf);
	if (ret == -1) {
		LOG(L_ERR, "challenge(): Error while sending response\n");
		return -1;
	}
	
	return 0;
}
Esempio n. 7
0
static int cmd_sniffer_control_start(struct sigma_dut *dut,
				     struct sigma_conn *conn,
				     struct sigma_cmd *cmd)
{
	const char *filename = get_param(cmd, "filename");
	int res;
	pid_t pid;

	if (dut->sniffer_pid) {
		sigma_dut_print(dut, DUT_MSG_INFO, "Sniffer was already capturing - restart based on new parameters");
		sniffer_close(dut);
	}

	if (filename == NULL) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Missing filename argument");
		return 0;
	}
	if (strchr(filename, '/')) {
		send_resp(dut, conn, SIGMA_ERROR, "errorCode,Invalid filename");
		return 0;
	}

	res = cmd_wlantest_set_channel(dut, conn, cmd);
	if (res != 1)
		return res;

	mkdir("Captures", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);

	sigma_dut_print(dut, DUT_MSG_INFO, "Starting sniffer process");
	snprintf(dut->sniffer_filename, sizeof(dut->sniffer_filename),
		 "Captures/%s", filename);
	pid = fork();
	if (pid < 0) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed to fork sniffer process");
		return 0;
	}

	if (pid == 0) {
		capture_process(dut->sniffer_ifname, dut->sniffer_filename);
		return 0;
	}

	dut->sniffer_pid = pid;

	return 1;
}
Esempio n. 8
0
auth_diam_result_t diam_pre_auth(struct sip_msg* _m, str* _realm, int _hftype, 
													struct hdr_field** _h)
{
	int ret;
	struct sip_uri uri;
	str realm;

	if ((_m->REQ_METHOD == METHOD_ACK) ||  (_m->REQ_METHOD == METHOD_CANCEL))
		return AUTHORIZED;

	/* if no realm supplied, find out now */
	if (_realm==0 || _realm->len == 0) 
	{
		if (get_realm(_m, _hftype, &uri) < 0) 
		{
			LM_ERR("failed to extract realm\n");
			if (send_resp(_m, 400, &dia_400_err, 0, 0) == -1) 
			{
				LM_ERR("failed to send 400 reply\n");
			}
			return ERROR;
		}
		realm = uri.host;
	} else {
		realm = *_realm;
	}

	ret = find_credentials(_m, &realm, _hftype, _h);
	if (ret < 0) 
	{
		LM_ERR("credentials not found\n");
		if (send_resp(_m, (ret == -2) ? 500 : 400, 
			      (ret == -2) ? &dia_500_err : &dia_400_err, 0, 0) == -1) 
		{
			LM_ERR("failed to send 400 reply\n");
		}
		return ERROR;
	} 
	else 
		if (ret > 0) 
		{
			LM_ERR("credentials with given realm not found\n");
			return NO_CREDENTIALS;
		}
	

	return DO_AUTHORIZATION;
}
Esempio n. 9
0
// send value of digital pin
void ORCPClass::sendDigital(byte pin, int value) 
{
  byte data[2];
  data[0] = pin;
  data[1] = value;
  send_resp(data, 2);
}
Esempio n. 10
0
/*
 * Purpose of this function is to do post authentication steps like
 * marking authorized credentials and so on.
 */
auth_result_t post_auth(struct sip_msg* _m, struct hdr_field* _h)
{
    int res = AUTHORIZED;
    auth_body_t* c;

    c = (auth_body_t*)((_h)->parsed);

    if (is_nonce_stale(&c->digest.nonce)) {
        if ((_m->REQ_METHOD == METHOD_ACK) ||
                (_m->REQ_METHOD == METHOD_CANCEL)) {
            /* Method is ACK or CANCEL, we must accept stale
             * nonces because there is no way how to challenge
             * with new nonce (ACK has no response associated
             * and CANCEL must have the same CSeq as the request
             * to be canceled)
             */
        } else {
            LM_DBG("response is OK, but nonce is stale\n");
            c->stale = 1;
            res = STALE_NONCE;
        }
    }

    if (mark_authorized_cred(_m, _h) < 0) {
        LM_ERR("failed to mark parsed credentials\n");
        if (send_resp(_m, 500, &auth_400_err, 0, 0) == -1) {
            LM_ERR("failed to send 500 reply\n");
        }
        res = ERROR;
    }

    return res;
}
Esempio n. 11
0
/*
 * Purpose of this function is to do post authentication steps like
 * marking authorized credentials and so on.
 */
auth_result_t post_auth(struct sip_msg* _m, struct hdr_field* _h, str* _rpid)
{
	int res = AUTHORIZED;
	auth_body_t* c;

	c = (auth_body_t*)((_h)->parsed);

	if (is_nonce_stale(&c->digest.nonce)) {
		if ((_m->REQ_METHOD == METHOD_ACK) || 
		    (_m->REQ_METHOD == METHOD_CANCEL)) {
			     /* Method is ACK or CANCEL, we must accept stale
			      * nonces because there is no way how to challenge
			      * with new nonce (ACK has no response associated 
			      * and CANCEL must have the same CSeq as the request 
			      * to be cancelled)
			      */
		} else {
			DBG("post_auth(): Response is OK, but nonce is stale\n");
			c->stale = 1;
			res = NOT_AUTHORIZED;
		}
	}

	if (mark_authorized_cred(_m, _h) < 0) {
		LOG(L_ERR, "post_auth(): Error while marking parsed credentials\n");
		if (send_resp(_m, 500, MESSAGE_500, 0, 0) == -1) {
			LOG(L_ERR, "post_auth(): Error while sending 500 reply\n");
		}
		res = ERROR;
	}

	save_rpid(_rpid);
	return res;
}
Esempio n. 12
0
static void
sparclite_serial_write (bfd *from_bfd, asection *from_sec, file_ptr from_addr,
			bfd_vma to_addr, int len)
{
  char buffer[4 + 4 + WRITESIZE];	/* addr + len + data */
  unsigned char checksum;
  int i;

  store_unsigned_integer (buffer, 4, to_addr);	/* Address */
  store_unsigned_integer (buffer + 4, 4, len);	/* Length */

  bfd_get_section_contents (from_bfd, from_sec, buffer + 8, from_addr, len);

  checksum = 0;
  for (i = 0; i < len; i++)
    checksum += buffer[8 + i];

  i = send_resp (remote_desc, 0x01);

  if (i != 0x5a)
    error ("Bad response from load command (0x%x)", i);

  debug_serial_write (remote_desc, buffer, 4 + 4 + len);
  i = readchar (remote_desc, remote_timeout);

  if (i != checksum)
    error ("Bad checksum from load command (0x%x)", i);
}
Esempio n. 13
0
static int cmd_sniffer_get_field_value(struct sigma_dut *dut,
				       struct sigma_conn *conn,
				       struct sigma_cmd *cmd)
{
	const char *infile = get_param(cmd, "FileName");
	const char *srcmac = get_param(cmd, "SrcMac");
	const char *framename = get_param(cmd, "FrameName");
	const char *fieldname = get_param(cmd, "FieldName");
	char buf[500], *pos;
	FILE *f;

	if (infile == NULL || srcmac == NULL || framename == NULL ||
	    fieldname == NULL)
		return -1;

	if (!file_exists("sniffer-get-field-value.py")) {
		send_resp(dut, conn, SIGMA_ERROR, "errorCode,sniffer-get-field-value.py not found");
		return 0;
	}

	snprintf(buf, sizeof(buf),
		 "./sniffer-get-field-value.py FileName=Captures/%s SrcMac=%s FrameName=%s FieldName=%s",
		 infile, srcmac, framename, fieldname);
	sigma_dut_print(dut, DUT_MSG_INFO, "Run: %s", buf);
	f = popen(buf, "r");
	if (f == NULL) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed to run sniffer helper");
		return 0;
	}

	if (!fgets(buf, sizeof(buf), f)) {
		pclose(f);
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed extract response from sniffer helper");
		return 0;
	}
	pos = strchr(buf, '\n');
	if (pos)
		*pos = '\0';

	pclose(f);

	send_resp(dut, conn, SIGMA_COMPLETE, buf);
	return 0;
}
Esempio n. 14
0
auth_result_t pre_auth(struct sip_msg* _m, str* _realm, int _hftype, struct hdr_field** _h)
{
	int ret;
	struct sip_uri uri;

	if ((_m->REQ_METHOD == METHOD_ACK) ||  (_m->REQ_METHOD == METHOD_CANCEL))
		return AUTHORIZED;

	/* if no realm supplied, find out now */
	if (_realm==0 || _realm->len == 0) 
	{
		if (get_realm(_m, _hftype, &uri) < 0) 
		{
			LOG(L_ERR, M_NAME":pre_auth(): Error while extracting realm\n");
			if (send_resp(_m, 400, MESSAGE_400, 0, 0) == -1) 
			{
				LOG(L_ERR, M_NAME":pre_auth(): Error while sending 400 reply\n");
			}
			return ERROR;
		}
		
		*_realm = uri.host;
	}

	ret = find_credentials(_m, _realm, _hftype, _h);
	if (ret < 0) 
	{
		LOG(L_ERR, M_NAME":pre_auth(): Error while looking for credentials\n");
		if (send_resp(_m, (ret == -2) ? 500 : 400, 
			      (ret == -2) ? MESSAGE_500 : MESSAGE_400, 0, 0) == -1) 
		{
			LOG(L_ERR, M_NAME":pre_auth(): Error while sending 400 reply\n");
		}
		return ERROR;
	} 
	else 
		if (ret > 0) 
		{
			LOG(L_ERR, M_NAME":pre_auth(): Credentials with given realm not "
				"found\n");
			return NO_CREDENTIALS;
		}
	

	return DO_AUTHORIZATION;
}
Esempio n. 15
0
static int handle_ota(int socket, char *recv_buf, int *exit_flag)
{
	char lua_ret[128] = "";
	char ota_ret[128] = "";
	unsigned int seqnum = 0;
	int ret = 0;
	OTA_ST ota_info;
	memset(&ota_info,0,sizeof(ota_info));

	seqnum = parse_json_seqnum(recv_buf);
	if(seqnum == -1) {
		//error format
		SEND_RESP(socket,"failure","Invalid OTA MSG",99,"ota");
	} else {
		if(0 == parse_json_ota_msg(recv_buf,&ota_info)) {
			//ok
			send_resp(socket,"success","Begin Download",seqnum,"ota");
			ret = do_ota(ota_info.url,ota_info.version,ota_ret,"/tmp/firmware.img");
			if(ret == 0) {
				memset(lua_ret,0,sizeof(lua_ret));
				NOTE("Get MD5:[%s]\n",ota_info.md5);
				read_file("/tmp/firmmd5",lua_ret,sizeof(lua_ret)-1);
		
				//lua_call_func("/etc/flashops.lua","action_flashops",
				//ota_info.md5,strlen(ota_info.md5),lua_ret);
				//if(strstr(lua_ret,"OK")) {
				if(strlen(ota_info.md5) == 32 && strstr(lua_ret,ota_info.md5)) {
					*exit_flag = 1;
					send_resp(socket,"success","Begin Flashing clear all",seqnum,"ota");
					system("/usr/bin/killall dropbear uhttpd crond");
					system("/sbin/sysupgrade -n /tmp/firmware.img");
					//exit_flag = 1;
				} else {
					ERROR("MD5 failed!%s\n",lua_ret);
					SEND_RESP(socket,"failure","md5 failed",seqnum,"ota");
				}
			} else {
				SEND_RESP(socket,"failure",ota_ret,seqnum,"ota");
			}
		} else {
			//error format
			SEND_RESP(socket,"failure","Invalid OTA MSG",seqnum,"ota");
		}
	}
	return 0;
}
Esempio n. 16
0
// send value of analog pin
void ORCPClass::sendAnalog(byte pin, int value) 
{
  byte data[3];
  data[0] = pin;
  data[1] = (byte)(value >> 8);
  data[2] = (byte)(0xFF & value);
  send_resp(data, 3);
}
Esempio n. 17
0
static int cmd_sniffer_check_p2p_noa_duration(struct sigma_dut *dut,
					      struct sigma_conn *conn,
					      struct sigma_cmd *cmd)
{
	FILE *f;
	char buf[200], *pos;
	const char *infile = get_param(cmd, "FileName");
	const char *bssid = get_param(cmd, "bssid");
	const char *srcmac = get_param(cmd, "srcmac");
	const char *destmac = get_param(cmd, "destmac");

	if (infile == NULL || bssid == NULL || srcmac == NULL ||
	    destmac == NULL)
		return -1;

	if (!file_exists("sniffer-check-p2p-noa-duration.py")) {
		send_resp(dut, conn, SIGMA_ERROR, "errorCode,sniffer-check-p2p-noa-duration.py not found");
		return 0;
	}

	snprintf(buf, sizeof(buf),
		 "./sniffer-check-p2p-noa-duration.py Captures/%s %s %s %s",
		 infile, bssid, srcmac, destmac);
	sigma_dut_print(dut, DUT_MSG_INFO, "Run: %s", buf);
	f = popen(buf, "r");
	if (f == NULL) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed to run sniffer check");
		return 0;
	}

	if (!fgets(buf, sizeof(buf), f)) {
		pclose(f);
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Failed extract response from sniffer check");
		return 0;
	}
	pos = strchr(buf, '\n');
	if (pos)
		*pos = '\0';

	pclose(f);

	send_resp(dut, conn, SIGMA_COMPLETE, buf);
	return 0;
}
Esempio n. 18
0
static int cmd_sniffer_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
				struct sigma_cmd *cmd)
{
	char buf[200];

	snprintf(buf, sizeof(buf), "WfaSnifferVersion,SigmaSniffer-foo,SnifferSTA,foo,DeviceSwInfo,foo,WiresharkVersion,foo");
	send_resp(dut, conn, SIGMA_COMPLETE, buf);
	return 0;
}
Esempio n. 19
0
static int cmd_sniffer_check_frame_field(struct sigma_dut *dut,
					 struct sigma_conn *conn,
					 struct sigma_cmd *cmd)
{
	char buf[200];

	/* TODO */
	snprintf(buf, sizeof(buf), "FilterStatus,SUCCESS");
	send_resp(dut, conn, SIGMA_COMPLETE, buf);
	return 0;
}
Esempio n. 20
0
static int cmd_sniffer_control_stop(struct sigma_dut *dut,
				    struct sigma_conn *conn,
				    struct sigma_cmd *cmd)
{
	if (!dut->sniffer_pid) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "errorCode,Sniffer was not capturing");
		return 0;
	}

	sniffer_close(dut);
	return 1;
}
Esempio n. 21
0
AW_Result
aw_default_post (AW_Session *sess, AW_Method method)
{
	const AW_Char *len_str, *data_str;
	AW_Size len;
	AW_Result r;

	len_str = aw_session_get_request(sess, "Content-Length");
	if (!len_str) {
		AW_ERROR(("cannot get content length"));
		send_resp(sess, 411);
		return AW_ERR_SYNTAX;
	}

	len = strtol(len_str, NULL, 10);
	if (len == LONG_MAX) {
		AW_ERROR(("illegal content length"));
		send_resp(sess, 400);
		return AW_ERR_SYNTAX;
	}

	r = recv_size(sess, len);
	if (r <= 0) {
		AW_ERROR(("receive post data failed"));
		send_resp(sess, 400);
		return AW_ERR_SYNTAX;
	}

	append_char(sess, 0);

	data_str = sess->buf + sess->pos;

	if ((r = aw_parse_params(data_str, &sess->post_hash)) != AW_OK) {
		send_resp(sess, 400);
		return r;
	}

	return aw_default_get(sess, AW_METHOD_GET);
}
Esempio n. 22
0
static err_t ps_accept_FPV_tcp_accept(void *arg, struct tcp_pcb *pcb, err_t err) {

	/* From inspection of the lwip source (core/tcp_in.c:639), 'err'
	 * will only ever be ERR_OK, so we can ignore it here.
	 */
	LWIP_UNUSED_ARG(err);

	/* Send a hello packet. */
	if (send_resp(pcb, RESP_ACK, '?', 0) < 0)
		return ERR_MEM;

	/* Call process_packet whenever we get data. */
	tcp_recv(pcb, process_packet_FPV_tcp_recv);

	return ERR_OK;
}
Esempio n. 23
0
static int cmd_sta_atheros(struct sigma_dut *dut, struct sigma_conn *conn,
			   struct sigma_cmd *cmd)
{
	char buf[2048], *pos;
	int i;
	const char *intf, *c;
	char resp[200];

	intf = get_param(cmd, "interface");
	c = get_param(cmd, "cmd");
	if (c == NULL)
		return -1;

	buf[0] = '\0';
	if (strncmp(c, "ctrl=", 5) == 0) {
		size_t rlen;
		c += 5;
		if (wpa_command_resp(intf, c, buf, sizeof(buf)) < 0)
			return -2;
		rlen = strlen(buf);
		if (rlen > 0 && buf[rlen - 1] == '\n')
			buf[rlen - 1] = '\0';
	} else if (strncmp(c, "timeout=", 8) == 0) {
		unsigned int timeout;
		timeout = atoi(c + 8);
		if (timeout == 0)
			return -1;
		dut->default_timeout = timeout;
		sigma_dut_print( DUT_MSG_INFO, "Set DUT default timeout "
				"to %u seconds", dut->default_timeout);
		snprintf(buf, sizeof(buf), "OK");
	} else
		return -2;

	i = snprintf(resp, sizeof(resp), "resp,");
	pos = buf;
	while (*pos && i + 1 < sizeof(resp)) {
		char c = *pos++;
		if (c == '\n' || c == '\r' || c == ',')
			c = '^';
		resp[i++] = c;
	}
	resp[i] = '\0';

	send_resp(dut, conn, SIGMA_COMPLETE, resp);
	return 0;
}
Esempio n. 24
0
unsigned int __stdcall handle_client(void *data)
{
	puts("handle Client");
	SOCKET client = *(SOCKET *)data;

    // max header size
	static char chunk[8190];

	if (recv(client, chunk, sizeof(chunk), 0) == -1) // should it be == -1 ?
	{
		err("Error handling incoming request");
	}

	puts(chunk);
	send_resp(client);

	return 0;
}
Esempio n. 25
0
/*
 * Purpose of this function is to find credentials with given realm,
 * do sanity check, validate credential correctness and determine if
 * we should really authenticate (there must be no authentication for
 * ACK and CANCEL
 */
auth_result_t pre_auth(struct sip_msg* _m, str* _realm, int _hftype, struct hdr_field** _h)
{
	int ret;
	auth_body_t* c;
	struct sip_uri uri;

	     /* ACK and CANCEL must be always authorized, there is
	      * no way how to challenge ACK and CANCEL cannot be
	      * challenged because it must have the same CSeq as
	      * the request to be cancelled
	      */

	if ((_m->REQ_METHOD == METHOD_ACK) ||  (_m->REQ_METHOD == METHOD_CANCEL)) return AUTHORIZED;

	if (_realm->len == 0) {
		if (get_realm(_m, _hftype, &uri) < 0) {
			LOG(L_ERR, "pre_auth(): Error while extracting realm\n");
			if (send_resp(_m, 400, MESSAGE_400, 0, 0) == -1) {
				LOG(L_ERR, "pre_auth(): Error while sending 400 reply\n");
			}
			return ERROR;
		}
		
		*_realm = uri.host;
		strip_realm(_realm);
	}

	     /* Try to find credentials with corresponding realm
	      * in the message, parse them and return pointer to
	      * parsed structure
	      */
	ret = find_credentials(_m, _realm, _hftype, _h);
	if (ret < 0) {
		LOG(L_ERR, "pre_auth(): Error while looking for credentials\n");
		if (send_resp(_m, (ret == -2) ? 500 : 400, 
			      (ret == -2) ? MESSAGE_500 : MESSAGE_400, 0, 0) == -1) {
			LOG(L_ERR, "pre_auth(): Error while sending 400 reply\n");
		}
		return ERROR;
	} else if (ret > 0) {
		DBG("pre_auth(): Credentials with given realm not found\n");
		return NOT_AUTHORIZED;
	}

	     /* Pointer to the parsed credentials */
	c = (auth_body_t*)((*_h)->parsed);

	     /* Check credentials correctness here */
	if (check_dig_cred(&(c->digest)) != E_DIG_OK) {
		LOG(L_ERR, "pre_auth(): Credentials received are not filled properly\n");
		if (send_resp(_m, 400, MESSAGE_400, 0, 0) == -1) {
			LOG(L_ERR, "pre_auth(): Error while sending 400 reply\n");
		}
		return ERROR;
	}

	if (check_nonce(&c->digest.nonce, &secret) != 0) {
		DBG("pre_auth(): Invalid nonce value received\n");
		return NOT_AUTHORIZED;
	}

	return DO_AUTHORIZATION;
}
Esempio n. 26
0
int
main(int argc, char *argv[])
{
		
		int port;
		char* file_img;
		int rfd;

		//Get the arguments
		get_args(&port, &file_img, argc, argv);
		
    int sd = UDP_Open(port); //Creates a new socket and binds to a port to it
    assert(sd > -1);

		//Open the file image, if not present call file_create routine
		disk_fd = open(file_img, O_RDWR);
		if(disk_fd == -1)
		{
			#ifdef DEBUG
				printf("----File image doesn't exist - Creating a new one\n");
			#endif
			
			rfd =	create_img(file_img);
			if(rfd == -1)
			{
				#ifdef DEBUG
					printf("----Error Creating the file - Exiting\n");
				#endif
				return -1;
			}
			disk_fd = rfd;
		}

#ifdef DEBUG
		printf("----File descriptor open: %d\n", disk_fd);
#endif

		printf("                                SERVER:: waiting in loop\n");
		
    while (1) 
		{
			struct sockaddr_in s;
			char buffer[MSG_BUFFER_SIZE];					//Redefined the size as, it may recieve more than 4096 bytes
	
			int rc = UDP_Read(sd, &s, buffer, MSG_BUFFER_SIZE);
			
			if (rc > 0) 
			{
	    	printf("                            	SERVER:: Read %d bytes (message: '%s')\n", rc, buffer);
	 
				int ret_func = parse_msg(buffer);   //Parse the message
				
				//Common paramters across all routines
				int pinum, inum, type, block, entries;
				char name[NAME_SIZE];
				char rw_buf[MFS_BLOCK_SIZE];
				char buf[MSG_BUFFER_SIZE];
				int res_t, ret;  //res_t- return status of server side routines
				S_Stat_t m;

				switch(ret_func)
				{
					case 1:
						ret = Lookup_parse(buffer, &pinum, &name);
						if (!ret)
							res_t = S_Lookup(pinum, name);
						else
							res_t = -1;
						
						//MSG Format: Function_id, Success_state(-1 or inum)
						memset(buf, 0, MSG_BUFFER_SIZE);
						snprintf(buf, 2*sizeof(int) , "%d%d", ret_func, res_t);
						send_resp(sd, &s, buf);
						break;
					case 2:
						ret = Stat_parse(buffer, &inum);
						if(!ret)
							res_t = S_Stat(inum, &m);
						else
							res_t = -1;
						
						//MSG Format: Function_id, Success_State, File_type, File_size
						memset(buf, 0, MSG_BUFFER_SIZE);
						snprintf(buf, 4*sizeof(int) , "%d%d%d%04d", ret_func, res_t, m.type, m.size);
						send_resp(sd, &s, buf);
						break;
					case 3:
						ret = Write_parse(buffer, &inum, &rw_buf, &block);
						if(!ret)
							res_t = S_Write(inum, rw_buf, block);
						else
							res_t = -1;

						//MSG Format: Function_id, Success_state
						memset(buf, 0, MSG_BUFFER_SIZE);
						snprintf(buf, 2*sizeof(int) , "%d%d", ret_func, res_t);
						send_resp(sd, &s, buf);
						break;
					case 4:
						ret = Read_parse(buffer, &inum, &block);
						if(!ret)
							res_t = S_Read(inum, &rw_buf, block, &type, &entries);
						else
							res_t = -1;
						
						//MSG Format: Function_id, Success_state, File_type, Num_of_entries, 4K buffer bytes read
						memset(buf, 0, MSG_BUFFER_SIZE);
						snprintf(buf, 4*sizeof(int) , "%d%d%d%02d", ret_func, res_t, type, entries);
						strcat(buf, rw_buf);
						send_resp(sd, &s, buf);
						break;
					case 5:
						ret = Creat_parse(buffer, &pinum, &type, &name);
						if(!ret)
							res_t = S_Creat(pinum, type, name);
						else
							res_t = -1;
						
						//MSG Format: Function_id, Success_state
						memset(buf, 0, MSG_BUFFER_SIZE);
						snprintf(buf, 2*sizeof(int) , "%d%d", ret_func, res_t);
						send_resp(sd, &s, buf);
						break;
					case 6:
						ret = Unlink_parse(buffer, &pinum, &name);
						break;
					case 7:
#ifdef DEBUG
						printf("----MFS_Shutdown called\n");
#endif
						break;
					default:
#ifdef DEBUG
						printf("Invalid Function Id\n");
#endif
						ret = -1;
						break;
				}
				
			}														//rc > 0 loop

    }														//while loop

    return 0;
}
Esempio n. 27
0
/* Authorize digest credentials */
int authorize(struct sip_msg* msg, str* realm, int hftype)
{
	auth_result_t ret;
	struct hdr_field* h;
	auth_body_t* cred = NULL;
	str* uri;
	struct sip_uri puri;
	str  domain;

	domain = *realm;

	/* see what is to do after a first look at the message */
	ret = pre_auth(msg, &domain, hftype, &h);
	
	switch(ret) 
	{
		case ERROR:            return 0;
			   
		case AUTHORIZED:       return 1;

		case NO_CREDENTIALS:   cred = NULL;
							   break;

		case DO_AUTHORIZATION: cred = (auth_body_t*)h->parsed;
							   break;
	}

	if (get_uri(msg, &uri) < 0) 
	{
		LOG(L_ERR, M_NAME":authorize(): From/To URI not found\n");
		return -1;
	}
	
	if (parse_uri(uri->s, uri->len, &puri) < 0) 
	{
		LOG(L_ERR, M_NAME":authorize(): Error while parsing From/To URI\n");
		return -1;
	}
//	user.s = (char *)pkg_malloc(puri.user.len);
//	un_escape(&(puri.user), &user);
	
	/* parse the ruri, if not yet */
	if(msg->parsed_uri_ok==0 && parse_sip_msg_uri(msg)<0)
	{
		LOG(L_ERR,M_NAME":authorize(): ERROR while parsing the Request-URI\n");
		return -1;
	}
	
	/* preliminary check */
	if(cred)
	{
		if (puri.host.len != cred->digest.realm.len) 
		{
			DBG(M_NAME":authorize(): Credentials realm and URI host do not "
				"match\n");  
			return -1;
		}
	
		if (strncasecmp(puri.host.s, cred->digest.realm.s, puri.host.len) != 0) 
		{
			DBG(M_NAME":authorize(): Credentials realm and URI host do not "
				"match\n");
			return -1;
		}
	}
	
	if( diameter_authorize(cred?h:NULL, &msg->first_line.u.request.method,
					puri, msg->parsed_uri, msg->id, rb) != 1)
	{
		send_resp(msg, 500, "Internal Server Error", NULL, 0);	
		return -1;
	}
	
	if( srv_response(msg, rb, hftype) != 1 )
		return -1;

	mark_authorized_cred(msg, h);

	return 1;
}
Esempio n. 28
0
static int cmd_traffic_send_ping(struct sigma_dut *dut,
				 struct sigma_conn *conn,
				 struct sigma_cmd *cmd)
{
	const char *dst, *val;
	int size, dur, pkts;
	int id;
	char resp[100];
	float interval;
	double rate;
	FILE *f;
	char buf[100];
	int type = 1;
	int dscp = 0, use_dscp = 0;
	char extra[100], int_arg[100], intf_arg[100];

	val = get_param(cmd, "Type");
	if (!val)
		val = get_param(cmd, "IPType");
	if (val)
		type = atoi(val);
	if (type != 1 && type != 2) {
		send_resp(dut, conn, SIGMA_ERROR,
			  "ErrorCode,Unsupported address type");
		return 0;
	}

	dst = get_param(cmd, "destination");
	if (dst == NULL || (type == 1 && !is_ip_addr(dst)) ||
	    (type == 2 && !is_ipv6_addr(dst)))
		return -1;

	val = get_param(cmd, "frameSize");
	if (val == NULL)
		return -1;
	size = atoi(val);

	val = get_param(cmd, "frameRate");
	if (val == NULL)
		return -1;
	rate = atof(val);
	if (rate <= 0)
		return -1;

	val = get_param(cmd, "duration");
	if (val == NULL)
		return -1;
	dur = atoi(val);
	if (dur <= 0 || dur > 3600)
		dur = 3600;

	pkts = dur * rate;
	interval = (float) 1 / rate;
	if (interval > 100000)
		return -1;

	val = get_param(cmd, "DSCP");
	if (val) {
		dscp = atoi(val);
		if (dscp < 0 || dscp > 63) {
			send_resp(dut, conn, SIGMA_ERROR,
				  "ErrorCode,Invalid DSCP value");
			return 0;
		}
		use_dscp = 1;
	}

	id = dut->next_streamid++;
	snprintf(buf, sizeof(buf), SIGMA_TMPDIR "/sigma_dut-ping.%d", id);
	unlink(buf);
	snprintf(buf, sizeof(buf), SIGMA_TMPDIR "/sigma_dut-ping-pid.%d", id);
	unlink(buf);

	sigma_dut_print(dut, DUT_MSG_DEBUG, "Send ping: pkts=%d interval=%f "
			"streamid=%d",
			pkts, interval, id);

	f = fopen(SIGMA_TMPDIR "/sigma_dut-ping.sh", "w");
	if (f == NULL)
		return -2;

	extra[0] = '\0';
	if (use_dscp) {
		snprintf(extra, sizeof(extra), " -Q 0x%02x",
			 dscp << 2);
	}

	int_arg[0] = '\0';
	if (rate != 1)
		snprintf(int_arg, sizeof(int_arg), " -i %f", interval);
	intf_arg[0] = '\0';
	if (type == 2)
		snprintf(intf_arg, sizeof(intf_arg), " -I %s",
			 get_station_ifname());
	fprintf(f, "#!" SHELL "\n"
		"ping%s -c %d%s -s %d%s -q%s %s > " SIGMA_TMPDIR
		"/sigma_dut-ping.%d &\n"
		"echo $! > " SIGMA_TMPDIR "/sigma_dut-ping-pid.%d\n",
		type == 2 ? "6" : "", pkts, int_arg, size, extra,
		intf_arg, dst, id, id);

	fclose(f);
	if (chmod(SIGMA_TMPDIR "/sigma_dut-ping.sh",
		  S_IRUSR | S_IWUSR | S_IXUSR) < 0)
		return -2;

	if (system(SIGMA_TMPDIR "/sigma_dut-ping.sh") != 0) {
		sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to start ping");
		return -2;
	}

	unlink(SIGMA_TMPDIR "/sigma_dut-ping.sh");

	snprintf(resp, sizeof(resp), "streamID,%d", id);
	send_resp(dut, conn, SIGMA_COMPLETE, resp);
	return 0;
}
Esempio n. 29
0
/*
 * Create and send a challenge
 */
static inline int challenge(struct sip_msg* _msg, gparam_p _realm, int _qop,
						int _code, char* _message, char* _challenge_msg)
{
	int auth_hf_len;
	struct hdr_field* h;
	auth_body_t* cred = 0;
	char *auth_hf;
	int ret;
	hdr_types_t hftype = 0; /* Makes gcc happy */
	struct sip_uri *uri;
	str realm;
	str reason;

	switch(_code) {
	case 401:
		get_authorized_cred(_msg->authorization, &h); 
		hftype = HDR_AUTHORIZATION_T;
		break;
	case 407:
		get_authorized_cred(_msg->proxy_auth, &h);
		hftype = HDR_PROXYAUTH_T;
		break;
	}

	if (h) cred = (auth_body_t*)(h->parsed);

	if(fixup_get_svalue(_msg, _realm, &realm)!=0)
	{
		LM_ERR("invalid realm parameter");
		if (send_resp(_msg, 500, &auth_500_err, 0, 0)==-1)
			return -1;
		else
			return 0;
	}
	if (realm.len == 0) {
		if (get_realm(_msg, hftype, &uri) < 0) {
			LM_ERR("failed to extract URI\n");
			if (send_resp(_msg, 400, &auth_400_err, 0, 0) == -1) {
				LM_ERR("failed to send the response\n");
				return -1;
			}
			return 0;
		}

		realm = uri->host;
		strip_realm(&realm);
	}

	auth_hf = build_auth_hf(0, (cred ? cred->stale : 0), &realm, 
			&auth_hf_len, _qop, _challenge_msg);
	if (!auth_hf) {
		LM_ERR("failed to generate nonce\n");
		return -1;
	}

	reason.s = _message;
	reason.len = strlen(_message);
	ret = send_resp(_msg, _code, &reason, auth_hf, auth_hf_len);
	if (auth_hf) pkg_free(auth_hf);
	if (ret == -1) {
		LM_ERR("failed to send the response\n");
		return -1;
	}
	
	return 0;
}
Esempio n. 30
0
/* Authorize digest credentials */
int authorize(struct sip_msg* msg, pv_elem_t* realm, int hftype)
{
	auth_result_t ret;
	struct hdr_field* h;
	auth_body_t* cred = NULL;
	str* uri;
	struct sip_uri puri;
	str  domain;

	if (realm) {
		if (pv_printf_s(msg, realm, &domain)!=0) {
			LM_ERR("pv_printf_s failed\n");
			return AUTH_ERROR;
		}
	} else {
		domain.len = 0;
		domain.s = 0;
	}

	/* see what is to do after a first look at the message */
	ret = diam_pre_auth(msg, &domain, hftype, &h);

	switch(ret)
	{
		case NO_CREDENTIALS:   cred = NULL;
							   break;

		case DO_AUTHORIZATION: cred = (auth_body_t*)h->parsed;
							   break;
		default:               return ret;
	}

	if (get_uri(msg, &uri) < 0)
	{
		LM_ERR("From/To URI not found\n");
		return AUTH_ERROR;
	}

	if (parse_uri(uri->s, uri->len, &puri) < 0)
	{
		LM_ERR("failed to parse From/To URI\n");
		return AUTH_ERROR;
	}
//	user.s = (char *)pkg_malloc(puri.user.len);
//	un_escape(&(puri.user), &user);

	/* parse the ruri, if not yet */
	if(msg->parsed_uri_ok==0 && parse_sip_msg_uri(msg)<0)
	{
		LM_ERR("failed to parse the Request-URI\n");
		return AUTH_ERROR;
	}

	/* preliminary check */
	if(cred)
	{
		if (puri.host.len != cred->digest.realm.len)
		{
			LM_DBG("credentials realm and URI host do not match\n");
			return AUTH_ERROR;
		}

		if (strncasecmp(puri.host.s, cred->digest.realm.s, puri.host.len) != 0)
		{
			LM_DBG("credentials realm and URI host do not match\n");
			return AUTH_ERROR;
		}
	}

	if( diameter_authorize(cred?h:NULL, &msg->first_line.u.request.method,
					puri, msg->parsed_uri, msg->id, rb) != 1)
	{
		send_resp(msg, 500, &dia_500_err, NULL, 0);
		return AUTH_ERROR;
	}

	if( srv_response(msg, rb, hftype) != 1 )
		return AUTH_ERROR;

	mark_authorized_cred(msg, h);

	return AUTHORIZED;
}