示例#1
0
文件: wapi.c 项目: pocketbook/801
static u8 * wpa_build_hdr(u8 *pos, u16 txseq, u8 stype)
{
	struct wai_hdr *hdr = (struct wai_hdr *)pos;
	
	SETSHORT(hdr->version, WAI_VERSION);
	hdr->type = WAI_TYPE;
	hdr->stype= stype;
	SETSHORT(hdr->reserve, 0);
	hdr->length = 0x0000;
	SETSHORT(hdr->rxseq, txseq);
	hdr->frag_sc = 0;
	hdr->more_frag = 0;
	return (u8 *)(hdr+1);
}
示例#2
0
文件: wapi.c 项目: pocketbook/801
static void wpa_put_frag(struct wapi_rxfrag *frag, u8 *data, int len)
{
	memcpy((unsigned char *)frag->data + frag->data_len, data, len);
	frag->data_len += len;

	{
		u16 tmp = (u16)frag->data_len;
		SETSHORT(((unsigned char *)(frag->data)+6), tmp);
	}
}
示例#3
0
static int
pass_OrNode(void *self, Pass pass, int level, void *par)
{
   VAR(OpNode, np, self);
   int no = np->op;

   switch (pass)
   {
   case Print:
      fprintfOffs(stdout, level, "OrNode label=%d\n", no);
      break;
   case PrintSrc:
      {
	 VAR(CodestrNode, cp, par);
	 VAR(StrBuf, out, cp->buf);
	 putString_StrBuf(out, "(");
	 np->expr1->pass(np->expr1, pass, level + 1, par);
	 putString_StrBuf(out, ".OR.");
	 np->expr2->pass(np->expr2, pass, level + 1, par);
	 putString_StrBuf(out, ")");
      }
      return 0;
   case CalcDeep:
      break;
   case CText:
      {
	 VAR(FILE, out, par);
	 np->expr1->pass(np->expr1, pass, level, par);
	 fprintfOffs(out, level, "if ((_ret=_clip_tcond( _mp, &_if ))) goto _trap_%d;\n", np->node.seqNo);
	 fprintfOffs(out, level, "if ( _if ) goto _endor_%d;\n", no);
	 fprintfOffs(out, level, "_clip_pop(_mp);\n");
	 np->expr2->pass(np->expr2, pass, level, par);
	 fprintfOffs(out, level, "_endor_%d:\n", no);
      }
      return 0;
   case OText:
      {
	 VAR(StrBuf, out, par);
	 int jmp;

	 np->expr1->pass(np->expr1, pass, level, par);

	 putByte_StrBuf(out, CLIP_ITCOND);
	 jmp = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	 putShort_StrBuf(out, 0);

	 putByte_StrBuf(out, CLIP_POP);
	 np->expr2->pass(np->expr2, pass, level, par);
	 SETSHORT(out, jmp, (out->ptr_of_StrBuf - out->buf_of_StrBuf) - (jmp + sizeof(short)));

      }
      return 0;
   case Traverse:
      {
	 VAR(TraversePar, tp, par);
	 tp->func((Node *) self, tp->par);
      }
      break;
   default:
      break;
   }
   np->expr1->pass(np->expr1, pass, level + 1, par);
   np->expr2->pass(np->expr2, pass, level + 1, par);
   return 0;
}
示例#4
0
static int
pass_IfNode(void *self, Pass pass, int level, void *par)
{
   VAR(IfNode, np, self);
   int i;

   switch (pass)
   {
   case Print:
      fprintfOffs(stdout, level, "IfNode :\n");
      break;
   case PrintSrc:
      {
	 VAR(CodestrNode, cp, par);
	 VAR(StrBuf, out, cp->buf);
	 putString_StrBuf(out, "iif(");
	 for (i = 0; i < np->elseifs->count_of_Coll; i += 2)
	 {
		 VAR(Node, p, np->elseifs->items_of_Coll[i]);
		 VAR(Node, lp, np->elseifs->items_of_Coll[i + 1]);
	    p->pass(p, pass, level, par);
	    putString_StrBuf(out, ",");
	    lp->pass(lp, pass, level, par);
	 }
	 putString_StrBuf(out, ",");
	 if (np->elselist)
	    np->elselist->pass(np->elselist, pass, level, par);
	 putString_StrBuf(out, ")");
      }
      return 0;
   case CalcDeep:
      {
	 VAR(Function, fp, par);
	 addDeep(fp, 1);
      }
      break;
   case CText:
      {
	 VAR(FILE, out, par);
	 int no = np->labelNo;

	 int eno = no + np->elseifs->count_of_Coll / 2 + (np->elselist ? 0 : -1);

	 print_line(self, level, out);
	 for (i = 0; i < np->elseifs->count_of_Coll; i += 2)
	 {
		 VAR(Node, p, np->elseifs->items_of_Coll[i]);
		 VAR(Node, lp, np->elseifs->items_of_Coll[i + 1]);
	    p->pass(p, pass, level, par);
	    fprintfOffs(out, level, "if ((_ret=_clip_cond( _mp, &_if ))) goto _trap_%d;\n", np->node.seqNo);
	    fprintfOffs(out, level, "if ( !_if ) goto _endif_%d_%d;\n", no, loopPart);
	    lp->pass(lp, pass, level, par);
	    fprintfOffs(out, level, "goto _endif_%d_%d;\n", eno, loopPart);
	    fprintfOffs(out, level, "_endif_%d_%d:\n", no, loopPart);
	    ++no;
	 }
	 if (np->elselist)
	 {
	    np->elselist->pass(np->elselist, pass, level, par);
	    fprintfOffs(out, level, "_endif_%d_%d:\n", no, loopPart);
	 }
      }
      return 0;
   case OText:
      {
	 VAR(StrBuf, out, par);
	 int no;

	 int count = np->elseifs->count_of_Coll / 2 + (np->elselist ? 0 : -1);

	 int eoffs;

	 int *ejmps = (int *) malloc(sizeof(int) * (count + 1));

	 put_line(self, level, out);
	 for (i = 0, no = 0; i < np->elseifs->count_of_Coll; i += 2, ++no)
	 {
		 VAR(Node, p, np->elseifs->items_of_Coll[i]);
		 VAR(Node, lp, np->elseifs->items_of_Coll[i + 1]);
	    int jmp;

	    p->pass(p, pass, level, par);
	    putByte_StrBuf(out, CLIP_COND);
	    jmp = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	    putShort_StrBuf(out, 0);
	    lp->pass(lp, pass, level, par);

	    if (no < count)
	    {
	       putByte_StrBuf(out, CLIP_GOTO);
	       ejmps[no] = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	       putShort_StrBuf(out, 0);
	    }

	    SETSHORT(out, jmp, (out->ptr_of_StrBuf - out->buf_of_StrBuf) - (jmp + sizeof(short)));
	 }
	 if (np->elselist)
	 {
	    np->elselist->pass(np->elselist, pass, level, par);
	 }
	 eoffs = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	 for (i = 0; i < count; ++i)
	 {
	    SETSHORT(out, ejmps[i], eoffs - (ejmps[i] + sizeof(short)));
	 }
	 free(ejmps);
      }
      return 0;
   case Traverse:
      {
	 VAR(TraversePar, tp, par);
	 tp->func((Node *) self, tp->par);
      }
      break;
   default:
      break;
   }
      for (i = 0; i < np->elseifs->count_of_Coll; i += 2)
   {
		VAR(Node, p, np->elseifs->items_of_Coll[i]);
		VAR(Node, lp, np->elseifs->items_of_Coll[i + 1]);
      p->pass(p, pass, level, par);
      lp->pass(lp, pass, level, par);
   }
   if (np->elselist)
      np->elselist->pass(np->elselist, pass, level, par);
   return 0;
}
示例#5
0
static int
pass_ForNode(void *self, Pass pass, int level, void *par)
{
   VAR(ForNode, np, self);
   switch (pass)
   {
   case Print:
      fprintfOffs(stdout, level, "ForNode :\n");
      break;
   case PrintSrc:
      {
	 yyerror("%s not allowed in CODESTR", np->node.name);
      }
      return 0;
   case CalcDeep:
      break;
   case CText:
      {
	 VAR(FILE, out, par);
	 int no = np->labelNo;

	 int saveNo = loopNo;

	 print_line(self, level, out);
	 loopPart = 0;
	 np->init->pass(np->init, pass, level, par);
	 np->to->pass(np->to, pass, level, par);
	 np->step->pass(np->step, pass, level, par);

	 fprintfOffs(out, level, "if ((_ret=_clip_forstep( _mp, &_if ))) goto _trap_%d;\n", np->node.seqNo);
	 fprintfOffs(out, level, "if ( !_if ) goto _endloop_%d;\n", no);

	 fprintfOffs(out, level, "goto _lbeg_%d;\n", no);

	 fprintfOffs(out, level, "_loop_%d:\n", no);
	 loopPart = 1;
	 np->var->pass(np->var, pass, level, par);
	 np->to->pass(np->to, pass, level, par);
	 np->step->pass(np->step, pass, level, par);
	 loopPart = 0;

	 fprintfOffs(out, level, "if ((_ret=_clip_forstep( _mp, &_if ))) goto _trap_%d;\n", np->node.seqNo);
	 fprintfOffs(out, level, "if ( !_if ) goto _endloop_%d;\n", no);

	 fprintfOffs(out, level, "_lbeg_%d:\n", no);

	 loopNo = no;
	 np->list->pass(np->list, pass, level, par);

	 fprintfOffs(out, level, "goto _loop_%d;\n", no);
	 fprintfOffs(out, level, "_endloop_%d:\n", no);
	 loopNo = saveNo;
      }
      return 0;
   case OText:
      {
	 VAR(StrBuf, out, par);
	 int jmp, eoffs, ibeg, lbeg, boffs;

	 LoopData ld;

	 put_line(self, level, out);
	 np->init->pass(np->init, pass, level, par);
	 np->to->pass(np->to, pass, level, par);
	 np->step->pass(np->step, pass, level, par);
	 putByte_StrBuf(out, CLIP_FORSTEP);
	 ibeg = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	 putShort_StrBuf(out, 0);

	 putByte_StrBuf(out, CLIP_GOTO);
	 lbeg = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	 putShort_StrBuf(out, 0);

	 boffs = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	 put_line(self, level, out);
	 np->var->pass(np->var, pass, level, par);
	 np->to->pass(np->to, pass, level, par);
	 np->step->pass(np->step, pass, level, par);
	 putByte_StrBuf(out, CLIP_FORSTEP);
	 jmp = out->ptr_of_StrBuf - out->buf_of_StrBuf;
	 putShort_StrBuf(out, 0);

	 SETSHORT(out, lbeg, (out->ptr_of_StrBuf - out->buf_of_StrBuf) - (lbeg + sizeof(short)));

	 np->list->pass(np->list, pass, level, par);

	 putByte_StrBuf(out, CLIP_GOTO);
	 eoffs = (out->ptr_of_StrBuf - out->buf_of_StrBuf) + sizeof(short);
	 putShort_StrBuf(out, boffs - eoffs);

	 SETSHORT(out, jmp, eoffs - (jmp + sizeof(short)));
	 SETSHORT(out, ibeg, eoffs - (ibeg + sizeof(short)));

	 ld.StrBuf_out_of_LoopData = out;
	 ld.boffs_of_LoopData = boffs;
	 ld.eoffs_of_LoopData = eoffs;
	 np->list->pass(np->list, OTextLoop, level, &ld);
      }
      return 0;
   case Traverse:
      {
	 VAR(TraversePar, tp, par);
	 tp->func((Node *) self, tp->par);
      }
      break;
   default:
      break;
   }

   np->init->pass(np->init, pass, level, par);
   np->step->pass(np->step, pass, level, par);
   np->var->pass(np->var, pass, level, par);
   np->to->pass(np->to, pass, level, par);
   np->list->pass(np->list, pass, level, par);

   return 0;
}
示例#6
0
文件: wapi.c 项目: pocketbook/801
static int waigroup_cert_2_3_send(struct wapi_asue_st* wpa_s, u8* payload, int len)
{
	static comm_data data_buff;
	static tsign				sign;
	u8 *sign_len_pos = NULL;
	static u8 tbuf[2048];
	u8 *pos = NULL;
	const struct cert_obj_st_t 	*cert_obj = NULL;

	payload = payload;/*disable warnning*/
	len = len;/*disable warnning*/
	
	iwn_wpa_printf(MSG_DEBUG, "WPA: in %s:%d", __func__, __LINE__);

	wapi_supplicant_key_negotiation_state_report(WPA_4WAY_HANDSHAKE);
	
	pos = tbuf;
	memset(pos, 0, sizeof(tbuf));
	memset(&data_buff, 0, sizeof(data_buff));
	memset(&sign, 0, sizeof(sign));
	
	pos = wpa_build_hdr(pos, ++wpa_s->txseq, WAI_ACCESS_AUTH_REQUEST);
	wpa_s->flag = BIT(2) |wpa_s->flag;
	iwn_wpa_printf(MSG_DEBUG, "WPA: in %s:%d,wpa_s->flag=%d", __func__, __LINE__,wpa_s->flag);
	*pos = wpa_s->flag;/*flag*/
	pos = pos + 1;
	pos= MEMCPY(pos, &(wpa_s->ae_auth_flag), 32);
	pos= MEMCPY(pos, &(wpa_s->Nasue), 32);
	pos= MEMCPY(pos, &(wpa_s->asue_key_data.length), 1);
	pos= MEMCPY(pos, &(wpa_s->asue_key_data.data), wpa_s->asue_key_data.length);
	
	SETSHORT(pos,wpa_s->ae_id.id_flag); pos += 2;
	SETSHORT(pos,wpa_s->ae_id.id_len); pos += 2;
	pos = MEMCPY(pos, wpa_s->ae_id.id_data, wpa_s->ae_id.id_len);
	#if 0
	{
		
		u16 tmp = wpa_s->ae_id.id_flag;
		pos = MEMCPY(pos, &(tmp), 2);
		tmp = iwn_htons(wpa_s->ae_id.id_len);
		pos = MEMCPY(pos, &(tmp), 2);
		pos = MEMCPY(pos, wpa_s->ae_id.id_data, wpa_s->ae_id.id_len);
	}
	#endif
	
	SETSHORT(pos,iwn_eloop.cert_info.config.used_cert); pos += 2;
	SETSHORT(pos,iwn_eloop.cert_info.asue_cert_obj->cert_bin->length); pos += 2;
	#if 0
	{
		u16 temp_len = iwn_htons(iwn_eloop.cert_info.config.used_cert);
		pos= MEMCPY(pos, &(temp_len), 2);
		temp_len = iwn_htons(iwn_eloop.cert_info.asue_cert_obj->cert_bin->length);
		pos= MEMCPY(pos, &(temp_len), 2);
	}
	#endif
	
	pos= MEMCPY(pos, iwn_eloop.cert_info.asue_cert_obj->cert_bin->data, iwn_eloop.cert_info.asue_cert_obj->cert_bin->length);/*ASUEÖ¤Êé*/
	iwn_wpa_hexdump(MSG_DEBUG, "cert_bin->data", iwn_eloop.cert_info.asue_cert_obj->cert_bin->data, iwn_eloop.cert_info.asue_cert_obj->cert_bin->length);

	*pos = wpa_s->ecdh.para_flag;   pos++;
	//pos= MEMCPY(pos, &(wpa_s->ecdh.para_flag), 1);/*ecdh*/
	SETSHORT(pos,wpa_s->ecdh.para_len); pos += 2;
	pos= MEMCPY(pos, &(wpa_s->ecdh.para_data), wpa_s->ecdh.para_len);/*ecdh*/
#if 0
	{
		u16 temp_len = iwn_htons(wpa_s->ecdh.para_len);
		pos= MEMCPY(pos, &(wpa_s->ecdh.para_flag), 1);/*ecdh*/
		pos= MEMCPY(pos, &temp_len, 2);/*ecdh*/
		pos= MEMCPY(pos, &(wpa_s->ecdh.para_data), wpa_s->ecdh.para_len);/*ecdh*/
	}
#endif
	data_buff.length = pos - tbuf - sizeof(struct wai_hdr);
	memcpy(data_buff.data, tbuf + sizeof(struct wai_hdr), data_buff.length);/*????*/
	cert_obj = get_cert_obj(iwn_eloop.cert_info.config.used_cert);
	iwn_wpa_printf(MSG_DEBUG, "WPA: in %s:%d,used_cert=%d", __func__, __LINE__,iwn_eloop.cert_info.config.used_cert);
	/*iwn_wpa_hexdump(MSG_DEBUG, "private_key ", cert_obj->private_key->data, cert_obj->private_key->length);*/

	if(!(*cert_obj->sign)(
		cert_obj->private_key->data,
		 cert_obj->private_key->length,
		data_buff.data, 	data_buff.length, sign.data))
	{
		iwn_wpa_printf(MSG_ERROR,"fail to sign data and will exit !!\n");
		return -1;
	}
	*pos ++= 1;
	sign_len_pos = pos;				
	pos += 2;/*length*/
	iwn_wpa_printf(MSG_DEBUG, "WPA: in %s:%d", __func__, __LINE__);

	SETSHORT(pos,iwn_eloop.asue_id.id_flag); pos += 2;
	SETSHORT(pos,iwn_eloop.asue_id.id_len); pos += 2;
	pos= MEMCPY(pos, &(iwn_eloop.asue_id.id_data), iwn_eloop.asue_id.id_len);
	
#if 0
	{
		u16 tmp_flag = 0;
		tmp_flag = iwn_htons(iwn_eloop.asue_id.id_flag);
		pos= MEMCPY(pos, &(tmp_flag), 2);
		tmp_flag = iwn_htons(iwn_eloop.asue_id.id_len);
		pos= MEMCPY(pos, &(tmp_flag), 2);
		pos= MEMCPY(pos, &(iwn_eloop.asue_id.id_data), iwn_eloop.asue_id.id_len);
	}
#endif

	SETSHORT(pos,wpa_s->sign_alg.alg_length); pos += 2;
	*pos = wpa_s->sign_alg.sha256_flag; pos++;
	*pos = wpa_s->sign_alg.sign_alg; pos++;
	*pos = wpa_s->sign_alg.sign_para.para_flag; pos++;
	SETSHORT(pos,wpa_s->sign_alg.sign_para.para_len); pos += 2;
	pos= MEMCPY(pos, &(wpa_s->sign_alg.sign_para.para_data), wpa_s->sign_alg.sign_para.para_len);
	SETSHORT(pos,SIGN_LEN); pos += 2;
	pos = MEMCPY(pos, &(sign.data), SIGN_LEN);
#if 0
	{
		u16 tmp_flag = 0;
		tmp_flag = iwn_htons(wpa_s->sign_alg.alg_length);
		pos= MEMCPY(pos, &(tmp_flag), 2);
		pos= MEMCPY(pos, &(wpa_s->sign_alg.sha256_flag), 1);
		pos= MEMCPY(pos, &(wpa_s->sign_alg.sign_alg), 1);
		pos= MEMCPY(pos, &(wpa_s->sign_alg.sign_para.para_flag), 1);
		tmp_flag = iwn_htons(wpa_s->sign_alg.sign_para.para_len);
		pos= MEMCPY(pos, &(tmp_flag), 2);
		pos= MEMCPY(pos, &(wpa_s->sign_alg.sign_para.para_data), wpa_s->sign_alg.sign_para.para_len);
		tmp_flag =iwn_htons( 48);
		pos= MEMCPY(pos, &(tmp_flag), 2);
		pos= MEMCPY(pos, &(sign.data), 48);
	}
#endif
	SETSHORT(sign_len_pos,(pos-sign_len_pos-2));
#if 0
	{
		u16 packet_len = 0;
		packet_len = iwn_htons((short)(pos-sign_len_pos-2));
		memcpy(sign_len_pos , &packet_len , 2);
	}
#endif	
	wpa_set_length(tbuf, (short)(pos-tbuf));
	iwn_wpa_ether_send(tbuf, pos-tbuf);
	timer_set(1, tbuf, pos-tbuf);

	wpa_s->wapi_state = WAPISM_CNT_REQ;

	return 0;
}
示例#7
0
文件: wapi.c 项目: pocketbook/801
static void wpa_set_length(u8 *pos, u16 length)
{
	SETSHORT((pos+6), length);
	//struct wai_hdr *hdr = (struct wai_hdr *)pos;
	//hdr->length = iwn_htons(length);
}