Esempio n. 1
0
/**
 * CommunicateThruEX
 *
 * @param[in]	Timeout			タイムアウト値[msec]
 * @param[in]	pCommand		送信するコマンド
 * @param[in]	CommandLen		pCommandの長さ
 * @param[out]	pResponse		レスポンス
 * @param[out]	pResponseLen	pResponseの長さ
 *
 * @retval		true			成功
 * @retval		false			失敗
 *
 * @note		-# Timeoutは往復分の時間を設定すること.
 */
bool NfcPcd_CommunicateThruEx(
			uint16_t Timeout,
			const uint8_t* pCommand, uint8_t CommandLen,
			uint8_t* pResponse, uint8_t* pResponseLen)
{
	//LOGD("%s : (%d)", __PRETTY_FUNCTION__, CommandLen);

	mNfcMng.frmbuf[0] = 0xd4;
	mNfcMng.frmbuf[1] = 0xa0;		//CommunicateThruEX
	mNfcMng.frmbuf[2] = l16(Timeout);
	mNfcMng.frmbuf[3] = h16(Timeout);
	if(CommandLen) {
		hk_memcpy(mNfcMng.frmbuf + 4, pCommand, CommandLen);
		CommandLen += 4;
	}

	uint16_t res_len;
	bool ret = sendCmd(mNfcMng.frmbuf, CommandLen, mNfcMng.resbuf, &res_len, true);
	if(!ret || (res_len < RESHEAD_LEN+1)) {
		LOGE("communicateThruEx ret=%d\n", ret);
		HkNfcRw_SetLastError(HKNFCERR_PCD_COMMTHRUEX);
		return false;
	}
	if(res_len == 3) {
		//Statusを返す
		pResponse[0] = mNfcMng.resbuf[POS_RESDATA];
		*pResponseLen = 1;
	} else {
		//Statusは返さない
		*pResponseLen = (uint8_t)(res_len - 3);
		hk_memcpy(pResponse, mNfcMng.resbuf + POS_RESDATA + 1, *pResponseLen);
	}

	return true;
}
Esempio n. 2
0
/**
 * @brief	ポーリング
 * 
 * NFC-Fのポーリングを行う.
 *
 * @param[in]		systemCode		システムコード
 * @retval			true			取得成功
 * @retval			false			取得失敗
 *
 * @retval		true			成功
 * @retval		false			失敗
 *
 * @attention	- 取得失敗は、主にカードが認識できない場合である。
 */
bool HkNfcF_Polling(uint16_t systemCode)
{
	//InListPassiveTarget
	const uint8_t INLISTPASSIVETARGET[] = {
		0x02,				// 0x01:212Kbps  0x02:424Kbps
		0x00,
		0xff, 0xff,			// SystemCode
		0x01,				// opt:0x01...get SystemCode
		0x0f				// Time Slot
	};
	const uint8_t INLISTPASSIVETARGET_RES[] = {
		0x01,				// System Number
		0x14,				// length(opt:+2)
		0x01				// response code
	};

	bool ret;
	uint8_t responseLen = 0;
	uint8_t* pData;
	uint8_t* pCmd = NfcPcd_CommandBuf();

	// 424Kbps
	hk_memcpy(pCmd, INLISTPASSIVETARGET, sizeof(INLISTPASSIVETARGET));
	pCmd[2] = h16(systemCode);
	pCmd[3] = l16(systemCode);

	ret = NfcPcd_InListPassiveTarget(
				pCmd, sizeof(INLISTPASSIVETARGET),
				&pData, &responseLen);
	if (!ret
	  || (hk_memcmp(&pData[3], INLISTPASSIVETARGET_RES, sizeof(INLISTPASSIVETARGET_RES)) != 0)) {
//		LOGE("pollingF fail(424Kbps): ret=%d/len=%d\n", ret, responseLen);

		//212Kbps
		pCmd[0] = 0x01;
		ret = NfcPcd_InListPassiveTarget(
				pCmd, sizeof(INLISTPASSIVETARGET),
				&pData, &responseLen);
		if (!ret
		  || (hk_memcmp(&pData[3], INLISTPASSIVETARGET_RES, sizeof(INLISTPASSIVETARGET_RES)) != 0)) {
//			LOGE("pollingF fail(212Kbps): ret=%d/len=%d\n", ret, responseLen);
			m_SystemCode = kSC_BROADCAST;
			return false;
		}
	}
	//[0] d5
	//[1] 4b
	//[2] NbTg
	//[3] Tg

	NfcPcd_SetNfcId(pData + 6, NFCID2_LEN);
	m_SystemCode = (uint16_t)(*(pData + 22) << 8 | *(pData + 23));

	return true;
}
Esempio n. 3
0
/**
 * @brief	書き込み
 * 
 * NFC-Fの指定したブロックに書き込む(1ブロック=16byte).
 *
 * @param[in]	pBuf		書き込みデータ(16byte=#HKNFCF_SZ_BLOCK)
 * @param[in]	BlockNo		書き込みブロック番号
 * @return		true		成功
 * @return		false		失敗
 */
bool HkNfcF_Write(const uint8_t* pBuf, uint8_t BlockNo)
{
	uint8_t len;
	uint8_t* pCmd = NfcPcd_CommandBuf();
	uint8_t* pRes = NfcPcd_ResponseBuf();
	
	pCmd[0] = (uint8_t)(14 + 2 + HKNFCF_SZ_BLOCK);		//len
	pCmd[1] = 0x08;		// Read w/o Enc.
	hk_memcpy(pCmd + 2, NfcPcd_NfcId(), NFCID2_LEN);
	pCmd[10] = 0x01;				//サービス数
#if 1
	pCmd[11] = l16(HKNFCF_SVCCODE_RW);
	pCmd[12] = h16(HKNFCF_SVCCODE_RW);
#else
	pCmd[11] = l16(m_SvcCode);
	pCmd[12] = h16(m_SvcCode);
#endif
	pCmd[13] = 0x01;			//ブロック数
	uint16_t blist = _create_blocklist2(BlockNo, AM_NORMAL, SCO_NORMAL);
	pCmd[14] = h16(blist);
	pCmd[15] = l16(blist);
	hk_memcpy(pCmd + 16, pBuf, HKNFCF_SZ_BLOCK);
	bool ret = NfcPcd_CommunicateThruEx(
					kDEFAULT_TIMEOUT,
					pCmd, pCmd[0],
					pRes, &len);
	if (!ret || (len != pRes[0]) || (pRes[0] != 12) || (pRes[1] != 0x09)
	  || (hk_memcmp(pRes + 2, NfcPcd_NfcId(), NFCID2_LEN) != 0)
	  || (pRes[10] != 0x00)
	  || (pRes[11] != 0x00)) {
		LOGE("read : ret=%d / %d / %d / %02x / %02x\n", ret, len, pRes[0], pRes[10], pRes[11]);
		return false;
	}

	return true;
}
Esempio n. 4
0
bool HkNfcF_SearchServiceCode(void)
{
	// Search Service Code
	uint8_t len;
	uint16_t loop = 0x0000;
	uint8_t* pCmd = NfcPcd_CommandBuf();
	uint8_t* pRes = NfcPcd_ResponseBuf();

	pCmd[0] = 12;
	pCmd[1] = 0x0a;
	hk_memcpy(pCmd + 2, NfcPcd_NfcId(), NFCID2_LEN);

	do {
		pCmd[10] = l16(loop);
		pCmd[11] = h16(loop);
		bool ret = NfcPcd_CommunicateThruEx(
							kDEFAULT_TIMEOUT,
							pCmd, 12,
							NfcPcd_ResponseBuf, &len);
		if (!ret || (pRes[0] != 0x0b)
		  || (memcmp(NfcPcd_ResponseBuf + 1, NfcPcd_NfcId(), NFCID2_LEN) != 0)) {
			LOGE("searchServiceCode : ret=%d\n", ret);
			return false;
		}

		len -= 9;
		const uint8_t* p = &pRes[9];
		if(len) {
			uint16_t svc = uint16_t((*(p+1) << 8) | *p);
#ifdef HKNFCRW_ENABLE_DEBUG
			uint16_t code = uint16_t((svc & 0xffc0) >> 6);
			uint8_t  attr = svc & 0x003f;
			if(len == 2) {
				LOGD("%04x(code:%04x : attr:%02x)\n", svc, code, attr);
			} else {
				LOGD("%04x(%s)\n", svc, (attr) ? "can" : "cannot");
			}
#endif

			//おしまいチェック
			if(svc == 0xffff) {
				break;
			}
			loop++;
		} else {
			break;
		}
	} while(true);
Esempio n. 5
0
static int
showdrec(int fd, int fmt, void *x)
{
	Drec *d = (Drec *)x;
	int namelen;
	int syslen;

	if(d->reclen == 0)
		return 0;
	fprint(fd, "%d %d %ld %ld ",
		d->reclen, d->attrlen, l32(d->addr), l32(d->size));
	fprint(fd, "%s 0x%2.2x %d %d %ld ",
		rdate(d->date, fmt), (fmt=='z' ? d->flags : d->r_flags),
		d->unitsize, d->gapsize, l16(d->vseqno));
	fprint(fd, "%d %s", d->namelen, nstr(d->name, d->namelen));
	if(fmt != 'J'){
		namelen = d->namelen + (1-(d->namelen&1));
		syslen = d->reclen - 33 - namelen;
		if(syslen != 0)
			fprint(fd, " %s", nstr(&d->name[namelen], syslen));
	}
	fprint(fd, "\n");
	return d->reclen + (d->reclen&1);
}
bool test(bool is_kernel_exact = true)
{
	// types
  typedef typename K::FT FT;
  typedef typename K::Line_3 Line;
  typedef typename K::Point_3 Point;
  typedef typename K::Segment_3 Segment;
  typedef typename K::Ray_3 Ray;
  typedef typename K::Line_3 Line;
  typedef typename K::Triangle_3 Triangle;

  /* -------------------------------------
  // Test data is something like that (in t supporting plane)
  // Triangle is (p1,p2,p3)
  //
  //       +E          +1
  //                 /   \
  //        +C     6+  +8  +4      +B
  //              /   9++7  \
  //            3+-------+5--+2
  //     
  //         +F        +A      
  ------------------------------------- */
  
  Point p1(FT(1.), FT(0.), FT(0.));
  Point p2(FT(0.), FT(1.), FT(0.));
  Point p3(FT(0.), FT(0.), FT(1.));
  
  Triangle t(p1,p2,p3);
  
  // Edges of t 
  Segment s12(p1,p2);
  Segment s21(p2,p1);
  Segment s13(p1,p3);
  Segment s23(p2,p3);
  Segment s32(p3,p2);
  Segment s31(p3,p1);
  
  bool b = test_aux(is_kernel_exact,t,s12,"t-s12",s12);
  b &= test_aux(is_kernel_exact,t,s21,"t-s21",s21);
  b &= test_aux(is_kernel_exact,t,s13,"t-s13",s13);
  b &= test_aux(is_kernel_exact,t,s23,"t-s23",s23);

  // Inside points
  Point p4(FT(0.5), FT(0.5), FT(0.));
  Point p5(FT(0.), FT(0.75), FT(0.25));
  Point p6(FT(0.5), FT(0.), FT(0.5));
  Point p7(FT(0.25), FT(0.625), FT(0.125));
  Point p8(FT(0.5), FT(0.25), FT(0.25));
  
  Segment s14(p1,p4);
  Segment s41(p4,p1);
  Segment s24(p2,p4);
  Segment s42(p4,p2);
  Segment s15(p1,p5);
  Segment s25(p2,p5);
  Segment s34(p3,p4);
  Segment s35(p3,p5);
  Segment s36(p3,p6);
  Segment s45(p4,p5);
  Segment s16(p1,p6);
  Segment s26(p2,p6);
  Segment s62(p6,p2);
  Segment s46(p4,p6);
  Segment s48(p4,p8);
  Segment s56(p5,p6);
  Segment s65(p6,p5);
  Segment s64(p6,p4);
  Segment s17(p1,p7);
  Segment s67(p6,p7);
  Segment s68(p6,p8);
  Segment s86(p8,p6);
  Segment s78(p7,p8);
  Segment s87(p8,p7);
  
  b &= test_aux(is_kernel_exact,t,s14,"t-s14",s14);
  b &= test_aux(is_kernel_exact,t,s41,"t-s41",s41);
  b &= test_aux(is_kernel_exact,t,s24,"t-s24",s24);
  b &= test_aux(is_kernel_exact,t,s42,"t-s42",s42);
  b &= test_aux(is_kernel_exact,t,s15,"t-s15",s15);
  b &= test_aux(is_kernel_exact,t,s25,"t-s25",s25);
  b &= test_aux(is_kernel_exact,t,s34,"t-s34",s34);
  b &= test_aux(is_kernel_exact,t,s35,"t-s35",s35);
  b &= test_aux(is_kernel_exact,t,s36,"t-s36",s36);
  b &= test_aux(is_kernel_exact,t,s45,"t-s45",s45);
  b &= test_aux(is_kernel_exact,t,s16,"t-s16",s16);
  b &= test_aux(is_kernel_exact,t,s26,"t-s26",s26);
  b &= test_aux(is_kernel_exact,t,s62,"t-s62",s62);
  b &= test_aux(is_kernel_exact,t,s46,"t-s46",s46);
  b &= test_aux(is_kernel_exact,t,s65,"t-s65",s65);
  b &= test_aux(is_kernel_exact,t,s64,"t-s64",s64);
  b &= test_aux(is_kernel_exact,t,s48,"t-s48",s48);
  b &= test_aux(is_kernel_exact,t,s56,"t-s56",s56);
  b &= test_aux(is_kernel_exact,t,s17,"t-t17",s17);
  b &= test_aux(is_kernel_exact,t,s67,"t-t67",s67);
  b &= test_aux(is_kernel_exact,t,s68,"t-s68",s68);
  b &= test_aux(is_kernel_exact,t,s86,"t-s86",s86);
  b &= test_aux(is_kernel_exact,t,s78,"t-t78",s78);
  b &= test_aux(is_kernel_exact,t,s87,"t-t87",s87);
  
  // Outside points (in triangle plane)
  Point pA(FT(-0.5), FT(1.), FT(0.5));
  Point pB(FT(0.5), FT(1.), FT(-0.5));
  Point pC(FT(0.5), FT(-0.5), FT(1.));
  Point pE(FT(1.), FT(-1.), FT(1.));
  Point pF(FT(-1.), FT(0.), FT(2.));
  
  Segment sAB(pA,pB);
  Segment sBC(pB,pC);
  Segment s2E(p2,pE);
  Segment sE2(pE,p2);
  Segment s2A(p2,pA);
  Segment s6E(p6,pE);
  Segment sB8(pB,p8);
  Segment sC8(pC,p8);
  Segment s8C(p8,pC);
  Segment s1F(p1,pF);
  Segment sF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,sAB,"t-sAB",p2);
  b &= test_aux(is_kernel_exact,t,sBC,"t-sBC",s46);
  b &= test_aux(is_kernel_exact,t,s2E,"t-s2E",s26);
  b &= test_aux(is_kernel_exact,t,sE2,"t-sE2",s62);
  b &= test_aux(is_kernel_exact,t,s2A,"t-s2A",p2);
  b &= test_aux(is_kernel_exact,t,s6E,"t-s6E",p6);
  b &= test_aux(is_kernel_exact,t,sB8,"t-sB8",s48);
  b &= test_aux(is_kernel_exact,t,sC8,"t-sC8",s68);
  b &= test_aux(is_kernel_exact,t,s8C,"t-s8C",s86);
  b &= test_aux(is_kernel_exact,t,s1F,"t-s1F",s13);
  b &= test_aux(is_kernel_exact,t,sF6,"t-sF6",s36);
  
  // Outside triangle plane
  Point pa(FT(0.), FT(0.), FT(0.));
  Point pb(FT(2.), FT(0.), FT(0.));
  Point pc(FT(1.), FT(0.), FT(1.));
  Point pe(FT(1.), FT(0.5), FT(0.5));
  
  Segment sab(pa,pb);
  Segment sac(pa,pc);
  Segment sae(pa,pe);
  Segment sa8(pa,p8);
  Segment sb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,sab,"t-sab",p1);
  b &= test_aux(is_kernel_exact,t,sac,"t-sac",p6);
  b &= test_aux(is_kernel_exact,t,sae,"t-sae",p8);
  b &= test_aux(is_kernel_exact,t,sa8,"t-sa8",p8);
  b &= test_aux(is_kernel_exact,t,sb2,"t-sb2",p2);
  
  // -----------------------------------
  // ray queries
  // -----------------------------------
  // Edges of t 
  Ray r12(p1,p2);
  Ray r21(p2,p1);
  Ray r13(p1,p3);
  Ray r23(p2,p3);
  
  b &= test_aux(is_kernel_exact,t,r12,"t-r12",s12);
  b &= test_aux(is_kernel_exact,t,r21,"t-r21",s21);
  b &= test_aux(is_kernel_exact,t,r13,"t-r13",s13);
  b &= test_aux(is_kernel_exact,t,r23,"t-r23",s23);
  
  // In triangle
  Point p9_(FT(0.), FT(0.5), FT(0.5));
  Point p9(FT(0.25), FT(0.375), FT(0.375));
  
  Ray r14(p1,p4);
  Ray r41(p4,p1);
  Ray r24(p2,p4);
  Ray r42(p4,p2);
  Ray r15(p1,p5);
  Ray r25(p2,p5);
  Ray r34(p3,p4);
  Ray r35(p3,p5);
  Ray r36(p3,p6);
  Ray r45(p4,p5);
  Ray r16(p1,p6);
  Ray r26(p2,p6);
  Ray r62(p6,p2);
  Ray r46(p4,p6);
  Ray r48(p4,p8);
  Ray r56(p5,p6);
  Ray r47(p4,p7);
  Ray r89(p8,p9);
  Ray r86(p8,p6);
  Ray r68(p6,p8);
  Segment r89_res(p8,p9_);
  
  b &= test_aux(is_kernel_exact,t,r14,"t-r14",s12);
  b &= test_aux(is_kernel_exact,t,r41,"t-r41",s41);
  b &= test_aux(is_kernel_exact,t,r24,"t-r24",s21);
  b &= test_aux(is_kernel_exact,t,r42,"t-r42",s42);
  b &= test_aux(is_kernel_exact,t,r15,"t-r15",s15);
  b &= test_aux(is_kernel_exact,t,r25,"t-r25",s23);
  b &= test_aux(is_kernel_exact,t,r34,"t-r34",s34);
  b &= test_aux(is_kernel_exact,t,r35,"t-r35",s32);
  b &= test_aux(is_kernel_exact,t,r36,"t-r36",s31);
  b &= test_aux(is_kernel_exact,t,r45,"t-r45",s45);
  b &= test_aux(is_kernel_exact,t,r16,"t-r16",s13);
  b &= test_aux(is_kernel_exact,t,r26,"t-r26",s26);
  b &= test_aux(is_kernel_exact,t,r62,"t-r62",s62);
  b &= test_aux(is_kernel_exact,t,r46,"t-r46",s46);
  b &= test_aux(is_kernel_exact,t,r48,"t-r48",s46);
  b &= test_aux(is_kernel_exact,t,r56,"t-r56",s56);
  b &= test_aux(is_kernel_exact,t,r47,"t-r47",s45);
  b &= test_aux(is_kernel_exact,t,r89,"t-t89",r89_res);
  b &= test_aux(is_kernel_exact,t,r68,"t-r68",s64);
  b &= test_aux(is_kernel_exact,t,r86,"t-r86",s86);
  
  
  // Outside points (in triangre prane)
  Ray rAB(pA,pB);
  Ray rBC(pB,pC);
  Ray r2E(p2,pE);
  Ray rE2(pE,p2);
  Ray r2A(p2,pA);
  Ray r6E(p6,pE);
  Ray rB8(pB,p8);
  Ray rC8(pC,p8);
  Ray r8C(p8,pC);
  Ray r1F(p1,pF);
  Ray rF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,rAB,"t-rAB",p2);
  b &= test_aux(is_kernel_exact,t,rBC,"t-rBC",s46);
  b &= test_aux(is_kernel_exact,t,r2E,"t-r2E",s26);
  b &= test_aux(is_kernel_exact,t,rE2,"t-rE2",s62);
  b &= test_aux(is_kernel_exact,t,r2A,"t-r2A",p2);
  b &= test_aux(is_kernel_exact,t,r6E,"t-r6E",p6);
  b &= test_aux(is_kernel_exact,t,rB8,"t-rB8",s46);
  b &= test_aux(is_kernel_exact,t,rC8,"t-rC8",s64);
  b &= test_aux(is_kernel_exact,t,r8C,"t-r8C",s86);
  b &= test_aux(is_kernel_exact,t,r1F,"t-r1F",s13);
  b &= test_aux(is_kernel_exact,t,rF6,"t-rF6",s31);
  
  // Outside triangle plane
  Ray rab(pa,pb);
  Ray rac(pa,pc);
  Ray rae(pa,pe);
  Ray ra8(pa,p8);
  Ray rb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,rab,"t-rab",p1);
  b &= test_aux(is_kernel_exact,t,rac,"t-rac",p6);
  b &= test_aux(is_kernel_exact,t,rae,"t-rae",p8);
  b &= test_aux(is_kernel_exact,t,ra8,"t-ra8",p8);
  b &= test_aux(is_kernel_exact,t,rb2,"t-rb2",p2);
  
  // -----------------------------------
  // Line queries
  // -----------------------------------
  // Edges of t 
  Line l12(p1,p2);
  Line l21(p2,p1);
  Line l13(p1,p3);
  Line l23(p2,p3);
  
  b &= test_aux(is_kernel_exact,t,l12,"t-l12",s12);
  b &= test_aux(is_kernel_exact,t,l21,"t-l21",s21);
  b &= test_aux(is_kernel_exact,t,l13,"t-l13",s13);
  b &= test_aux(is_kernel_exact,t,l23,"t-l23",s23);
  
  // In triangle
  Line l14(p1,p4);
  Line l41(p4,p1);
  Line l24(p2,p4);
  Line l42(p4,p2);
  Line l15(p1,p5);
  Line l25(p2,p5);
  Line l34(p3,p4);
  Line l35(p3,p5);
  Line l36(p3,p6);
  Line l45(p4,p5);
  Line l16(p1,p6);
  Line l26(p2,p6);
  Line l62(p6,p2);
  Line l46(p4,p6);
  Line l48(p4,p8);
  Line l56(p5,p6);
  Line l47(p4,p7);
  Line l89(p8,p9);
  Line l86(p8,p6);
  Line l68(p6,p8);
  Segment l89_res(p1,p9_);

  
  b &= test_aux(is_kernel_exact,t,l14,"t-l14",s12);
  b &= test_aux(is_kernel_exact,t,l41,"t-l41",s21);
  b &= test_aux(is_kernel_exact,t,l24,"t-l24",s21);
  b &= test_aux(is_kernel_exact,t,l42,"t-l42",s12);
  b &= test_aux(is_kernel_exact,t,l15,"t-l15",s15);
  b &= test_aux(is_kernel_exact,t,l25,"t-l25",s23);
  b &= test_aux(is_kernel_exact,t,l34,"t-l34",s34);
  b &= test_aux(is_kernel_exact,t,l35,"t-l35",s32);
  b &= test_aux(is_kernel_exact,t,l36,"t-l36",s31);
  b &= test_aux(is_kernel_exact,t,l45,"t-l45",s45);
  b &= test_aux(is_kernel_exact,t,l16,"t-l16",s13);
  b &= test_aux(is_kernel_exact,t,l26,"t-l26",s26);
  b &= test_aux(is_kernel_exact,t,l62,"t-l62",s62);
  b &= test_aux(is_kernel_exact,t,l46,"t-l46",s46);
  b &= test_aux(is_kernel_exact,t,l48,"t-l48",s46);
  b &= test_aux(is_kernel_exact,t,l56,"t-l56",s56);
  b &= test_aux(is_kernel_exact,t,l47,"t-l47",s45);
  b &= test_aux(is_kernel_exact,t,l89,"t-t89",l89_res);
  b &= test_aux(is_kernel_exact,t,l68,"t-l68",s64);
  b &= test_aux(is_kernel_exact,t,l86,"t-l86",s46);

  
  // Outside points (in triangle plane)
  Line lAB(pA,pB);
  Line lBC(pB,pC);
  Line l2E(p2,pE);
  Line lE2(pE,p2);
  Line l2A(p2,pA);
  Line l6E(p6,pE);
  Line lB8(pB,p8);
  Line lC8(pC,p8);
  Line l8C(p8,pC);
  Line l1F(p1,pF);
  Line lF6(pF,p6);
  
  b &= test_aux(is_kernel_exact,t,lAB,"t-lAB",p2);
  b &= test_aux(is_kernel_exact,t,lBC,"t-lBC",s46);
  b &= test_aux(is_kernel_exact,t,l2E,"t-l2E",s26);
  b &= test_aux(is_kernel_exact,t,lE2,"t-lE2",s62);
  b &= test_aux(is_kernel_exact,t,l2A,"t-l2A",p2);
  b &= test_aux(is_kernel_exact,t,l6E,"t-l6E",s26);
  b &= test_aux(is_kernel_exact,t,lB8,"t-lB8",s46);
  b &= test_aux(is_kernel_exact,t,lC8,"t-lC8",s64);
  b &= test_aux(is_kernel_exact,t,l8C,"t-l8C",s46);
  b &= test_aux(is_kernel_exact,t,l1F,"t-l1F",s13);
  b &= test_aux(is_kernel_exact,t,lF6,"t-lF6",s31);
  
  // Outside triangle plane
  Line lab(pa,pb);
  Line lac(pa,pc);
  Line lae(pa,pe);
  Line la8(pa,p8);
  Line lb2(pb,p2);
  
  b &= test_aux(is_kernel_exact,t,lab,"t-lab",p1);
  b &= test_aux(is_kernel_exact,t,lac,"t-lac",p6);
  b &= test_aux(is_kernel_exact,t,lae,"t-lae",p8);
  b &= test_aux(is_kernel_exact,t,la8,"t-la8",p8);
  b &= test_aux(is_kernel_exact,t,lb2,"t-lb2",p2);
  
  
	return b;
}
Esempio n. 7
0
static int
iattach(Xfile *root)
{
	Xfs *cd = root->xf;
	Iobuf *p; Voldesc *v; Isofile *fp; Drec *dp;
	int fmt, blksize, i, n, l, haveplan9;
	Iobuf *dirp;
	uint8_t dbuf[256];
	Drec *rd = (Drec *)dbuf;
	uint8_t *q, *s;

	dirp = nil;
	blksize = 0;
	fmt = 0;
	dp = nil;
	haveplan9 = 0;
	for(i=VOLDESC;i<VOLDESC+100; i++){	/* +100 for sanity */
		p = getbuf(cd->d, i);
		v = (Voldesc*)(p->iobuf);
		if(memcmp(v->byte, "\01CD001\01", 7) == 0){		/* iso */
			if(dirp)
				putbuf(dirp);
			dirp = p;
			fmt = 'z';
			dp = (Drec*)v->z.desc.rootdir;
			blksize = l16(v->z.desc.blksize);
			chat("iso, blksize=%d...", blksize);

			v = (Voldesc*)(dirp->iobuf);
			haveplan9 = (strncmp((char*)v->z.boot.sysid, "PLAN 9", 6)==0);
			if(haveplan9){
				if(noplan9) {
					chat("ignoring plan9");
					haveplan9 = 0;
				} else {
					fmt = '9';
					chat("plan9 iso...");
				}
			}
			continue;
		}

		if(memcmp(&v->byte[8], "\01CDROM\01", 7) == 0){	/* high sierra */
			if(dirp)
				putbuf(dirp);
			dirp = p;
			fmt = 'r';
			dp = (Drec*)v->r.desc.rootdir;
			blksize = l16(v->r.desc.blksize);
			chat("high sierra, blksize=%d...", blksize);
			continue;
		}

		if(haveplan9==0 && !nojoliet
		&& memcmp(v->byte, "\02CD001\01", 7) == 0){
chat("%d %d\n", haveplan9, nojoliet);
			/*
			 * The right thing to do is walk the escape sequences looking
			 * for one of 25 2F 4[035], but Microsoft seems to not honor
			 * the format, which makes it hard to walk over.
			 */
			q = v->z.desc.escapes;
			if(q[0] == 0x25 && q[1] == 0x2F && (q[2] == 0x40 || q[2] == 0x43 || q[2] == 0x45)){	/* Joliet, it appears */
				if(dirp)
					putbuf(dirp);
				dirp = p;
				fmt = 'J';
				dp = (Drec*)v->z.desc.rootdir;
				if(blksize != l16(v->z.desc.blksize))
					fprint(2, "warning: suspicious Joliet blocksize\n");
				chat("joliet...");
				continue;
			}
		}
		putbuf(p);
		if(v->byte[0] == 0xFF)
			break;
	}

	if(fmt == 0){
		if(dirp)
			putbuf(dirp);
		return -1;
	}
	assert(dirp != nil);

	if(chatty)
		showdrec(2, fmt, dp);
	if(blksize > Sectorsize){
		chat("blksize too big...");
		putbuf(dirp);
		return -1;
	}
	if(waserror()){
		putbuf(dirp);
		nexterror();
	}
	root->len = sizeof(Isofile) - sizeof(Drec) + dp->reclen;
	root->ptr = fp = ealloc(root->len);

	if(haveplan9)
		root->xf->isplan9 = 1;

	fp->fmt = fmt;
	fp->blksize = blksize;
	fp->offset = 0;
	fp->doffset = 0;
	memmove(&fp->d, dp, dp->reclen);
	root->qid.path = l32(dp->addr);
	root->qid.type = QTDIR;
	putbuf(dirp);
	poperror();
	if(getdrec(root, rd) >= 0){
		n = rd->reclen-(34+rd->namelen);
		s = (uint8_t*)rd->name + rd->namelen;
		if((uintptr)s & 1){
			s++;
			n--;
		}
		if(n >= 7 && s[0] == 'S' && s[1] == 'P' && s[2] == 7 &&
		   s[3] == 1 && s[4] == 0xBE && s[5] == 0xEF){
			root->xf->issusp = 1;
			root->xf->suspoff = s[6];
			n -= root->xf->suspoff;
			s += root->xf->suspoff;
			for(; n >= 4; s += l, n -= l){
				l = s[2];
				if(s[0] == 'E' && s[1] == 'R'){
					if(!norock && s[4] == 10 && memcmp(s+8, "RRIP_1991A", 10) == 0)
						root->xf->isrock = 1;
					break;
				} else if(s[0] == 'C' && s[1] == 'E' && s[2] >= 28){
					n = getcontin(root->xf->d, s, &s);
					continue;
				} else if(s[0] == 'R' && s[1] == 'R'){
					if(!norock)
						root->xf->isrock = 1;
					break;
				} else if(s[0] == 'S' && s[1] == 'T')
					break;
			}
		}
	}
	if(root->xf->isrock)
		chat("Rock Ridge...");
	fp->offset = 0;
	fp->doffset = 0;
	return 0;
}
Esempio n. 8
0
/**
 * TgInitAsTarget
 *
 * ターゲットとして起動する.
 * 応答はTgResponseToInitiatorで返す.
 *
 * [in,out]		pParam			ターゲットパラメータ
 * 
 * @retval		true			成功
 * @retval		false			失敗
 */
bool NfcPcd_TgInitAsTarget(TargetParam* pParam)
{
	//LOGD("%s", __PRETTY_FUNCTION__);

	uint16_t len = 0;

	mNfcMng.frmbuf[len++] = 0xd4;
	mNfcMng.frmbuf[len++] = 0x8c;				//TgInitAsTarget

	//mode
	//mNfcMng.frmbuf[len++] = 0x00;		// Card Emu. OK && active OK
	//mNfcMng.frmbuf[len++] = 0x01;		// Card Emu. OK && Passive Only
	mNfcMng.frmbuf[len++] = 0x02;		// DEP only && active OK
	//mNfcMng.frmbuf[len++] = 0x03;		// DEP only && Passive Only

	//MIFARE
	//SENS_RES
	mNfcMng.frmbuf[len++] = 0x00;
	mNfcMng.frmbuf[len++] = 0x04;		//0x00はだめ
	//NFCID1
#if 0
	if(pParam->pUId) {
		hk_memcpy(mNfcMng.frmbuf + len, pParam->pUId, 3);
		len += 3;
	} else {
		mNfcMng.frmbuf[len++] = rand() & 0xff;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
	}
#else
	mNfcMng.frmbuf[len++] = 0x12;
	mNfcMng.frmbuf[len++] = 0x34;
	mNfcMng.frmbuf[len++] = 0x56;
#endif
	//SEL_RES
	mNfcMng.frmbuf[len++] = 0x40;		//固定

	//FeliCaParams
	//IDm
	uint8_t idm_pos = len;
#if 0
	if(pParam->pIDm) {
		hk_memcpy(mNfcMng.frmbuf + len, pParam->pIDm, NFCID2_LEN);
		len += NFCID2_LEN;
	} else {
		//自動生成
		mNfcMng.frmbuf[len++] = 0x01;
		mNfcMng.frmbuf[len++] = 0xfe;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
		mNfcMng.frmbuf[len++] = rand() & 0xff;
	}
#else
	//自動生成
	mNfcMng.frmbuf[len++] = 0x01;
	mNfcMng.frmbuf[len++] = 0xfe;
	mNfcMng.frmbuf[len++] = 0x12;
	mNfcMng.frmbuf[len++] = 0x34;
	mNfcMng.frmbuf[len++] = 0x56;
	mNfcMng.frmbuf[len++] = 0x78;
	mNfcMng.frmbuf[len++] = 0x9a;
	mNfcMng.frmbuf[len++] = 0xbc;
#endif
	//PMm
	hk_memset(mNfcMng.frmbuf + len, 0xff, 8);
	len += 8;
	//SystemCode
#if 0
	mNfcMng.frmbuf[len++] = h16(pParam->SystemCode);
	mNfcMng.frmbuf[len++] = l16(pParam->SystemCode);
#else
	mNfcMng.frmbuf[len++] = 0xff;
	mNfcMng.frmbuf[len++] = 0xff;
#endif

	//NFCID3t
	hk_memcpy(mNfcMng.frmbuf + len, mNfcMng.frmbuf + idm_pos, NFCID2_LEN);
	len += NFCID2_LEN;
	mNfcMng.frmbuf[len++] = 0x00;
	mNfcMng.frmbuf[len++] = 0x00;

	//General Bytes
	if(pParam->GbLen) {
		hk_memcpy(mNfcMng.frmbuf + len, pParam->pGb, pParam->GbLen);
		len += pParam->GbLen;
	}


//	for(int i=0; i<len; i++) {
//		LOGD("%02x ", mNfcMng.frmbuf[i]);
//	}

	uint16_t res_len;
	bool ret = sendCmd(mNfcMng.frmbuf, len, mNfcMng.resbuf, &res_len, true);
	if(!ret || (res_len < RESHEAD_LEN+1)) {
		LOGE("fail : TgInitAsTarget ret=%d/len=%d\n", ret, res_len);
		HkNfcRw_SetLastError(HKNFCERR_PCD_TGINIT);
		return false;
	}

	if(pParam->pCommand) {
		//Activated情報以下
		pParam->CommandLen = (uint8_t)(res_len - 2);
		hk_memcpy(pParam->pCommand, mNfcMng.resbuf + 2, pParam->CommandLen);
	}

	return true;
}