Beispiel #1
0
/*
 *   Clear and Enable intterupt for keypad
 *     1. Deassert BU9929FV INT pin by I2C read
 *     2. Clear ICH2 GPIO[11] interrupt
 *     3. Enable watch function of BU9929FV
 *     4. Enable ICH2 GPIO[11] interrupt
 */
static void kpad_clear_and_enable_intr(void)
{
        __u16 dummy;

        /* clear interrupt */
        out_raw(0xff);                      /* no raw is asserted */
        bu9929gpio_in(0, &dummy);           /* clear BU9929 intr. */
        ichgpio_clear_intr(GPIO_SMBALERT);  /* clear ICH2 GPIO intr. */

        out_raw(0);                         /* assert all raw */

        /* enable interrupt */
        bu9929gpio_set_intrmode(0, BU9929_WATCH_ENABLE);
        ichgpio_enable_intr(GPIO_SMBALERT);
}
Beispiel #2
0
int kpad_scan_line( SCANINFO *sinfo, unsigned int i)
{
	__u8 	col, downkey, upkey;
	static __u8 row;
	unsigned int j;


	if (i == 0) row = 0x01;

	out_raw(~row);
	udelay(ROW_DELAY);

       	in_col(&col);
        sinfo->key[i] = col;

	if (~(sinfo->key[i]))
		sinfo->push_flg = 1;

	sinfo->diffkey[i] = sinfo->key[i] ^ sinfo->lastkey[i];

        if (sinfo->diffkey[i]) {
       		downkey = ~sinfo->key[i] & sinfo->diffkey[i];   /* key went down */
                upkey   = sinfo->key[i]  & sinfo->diffkey[i];   /* key went up   */

                for (j = 0, col=0x80; j < 8; j++, col >>= 1) {
			if (downkey & col)
                        	handle_scancode( KEYCODE(i, j), 1 );
                        else if ( upkey & col )
                        	handle_scancode( KEYCODE(i, j) | KBUP, 0 );
                }
        }
Beispiel #3
0
bool emit_redirect_notification_decoded_dest(
		v2_notification_t ntype,
		const ip_address *dest_ip,
		const char *dest_str,
		const chunk_t *nonce, /* optional */
		pb_stream *pbs)
{
	struct ikev2_redirect_part gwi;
	size_t id_len;
	const unsigned char *id_bytes;

	if (dest_ip == NULL) {
		id_len = strlen(dest_str);
		id_bytes = (const unsigned char *)dest_str;
	} else {
		passert(dest_str == NULL);

		switch (addrtypeof(dest_ip)) {
		case AF_INET:
			gwi.gw_identity_type = GW_IPV4;
			break;
		case AF_INET6:
			gwi.gw_identity_type = GW_IPV6;
			break;
		default:
			bad_case(addrtypeof(dest_ip));
		}
		id_len = addrbytesptr_read(dest_ip, &id_bytes);
	}

	if (id_len > 0xFF) {
		/* ??? what should we do? */
		loglog(RC_LOG_SERIOUS, "redirect destination longer than 255 octets; ignoring");
		return false;
	}
	gwi.gw_identity_len = id_len;

	passert(nonce == NULL ||
		(nonce->len >= IKEv2_MINIMUM_NONCE_SIZE &&
		 nonce->len <= IKEv2_MAXIMUM_NONCE_SIZE));

	pb_stream gwid_pbs;
	return
-		emit_v2Npl(ntype, pbs, &gwid_pbs) &&
		out_struct(&gwi, &ikev2_redirect_desc, &gwid_pbs, NULL) &&
		out_raw(id_bytes, id_len , &gwid_pbs, "redirect ID") &&
		(nonce == NULL || out_chunk(*nonce, &gwid_pbs, "redirect ID len")) &&
		(close_output_pbs(&gwid_pbs), true);
}
Beispiel #4
0
bool ikev2_calculate_rsa_sha1(struct state *st
			      , enum phase1_role role
			      , unsigned char *idhash
			      , pb_stream *a_pbs)
{
	unsigned char  signed_octets[SHA1_DIGEST_SIZE+16];
	size_t         signed_len;
	const struct connection *c = st->st_connection;
	const struct RSA_private_key *k = get_RSA_private_key(c);
	unsigned int sz;

	if (k == NULL)
	    return 0;	/* failure: no key to use */

	sz = k->pub.k;

        /*
         * this is the prefix of the ASN/DER goop that lives inside RSA-SHA1
         * signatures.  If the signing hash changes, this needs to change
         * too, but this function is specific to RSA-SHA1.
         */
	memcpy(signed_octets, der_digestinfo, der_digestinfo_len);

	ikev2_calculate_sighash(st, role, idhash
				, st->st_firstpacket_me
				, signed_octets+der_digestinfo_len);
	signed_len = der_digestinfo_len + SHA1_DIGEST_SIZE;

	passert(RSA_MIN_OCTETS <= sz && 4 + signed_len < sz && sz <= RSA_MAX_OCTETS);

	DBG(DBG_CRYPT
	    , DBG_dump("v2rsa octets", signed_octets, signed_len));

	{
		u_char sig_val[RSA_MAX_OCTETS];

		/* now generate signature blob */
		sign_hash(k, signed_octets, signed_len
			  , sig_val, sz);
		out_raw(sig_val, sz, a_pbs, "rsa signature");
	}

	return TRUE;
}
Beispiel #5
0
bool ikev2_calculate_rsa_sha1(struct state *st,
			      enum phase1_role role,
			      unsigned char *idhash,
			      pb_stream *a_pbs)
{
	unsigned char signed_octets[SHA1_DIGEST_SIZE + 16];
	size_t signed_len;
	const struct connection *c = st->st_connection;
	const struct RSA_private_key *k = get_RSA_private_key(c);
	unsigned int sz;

	if (k == NULL)
		return FALSE; /* failure: no key to use */

	sz = k->pub.k;

	memcpy(signed_octets, der_digestinfo, der_digestinfo_len);

	ikev2_calculate_sighash(st, role, idhash,
				st->st_firstpacket_me,
				signed_octets + der_digestinfo_len);
	signed_len = der_digestinfo_len + SHA1_DIGEST_SIZE;

	passert(RSA_MIN_OCTETS <= sz && 4 + signed_len < sz &&
		sz <= RSA_MAX_OCTETS);

	DBG(DBG_CRYPT,
	    DBG_dump("v2rsa octets", signed_octets, signed_len));

	{
		/* now generate signature blob */
		u_char sig_val[RSA_MAX_OCTETS];
		int shr;

		shr = sign_hash(k, signed_octets, signed_len, sig_val, sz);
		if (shr == 0)
			return FALSE;
		passert(shr == (int)sz);
		if (!out_raw(sig_val, sz, a_pbs, "rsa signature"))
			return FALSE;
	}

	return TRUE;
}
Beispiel #6
0
bool ikev2_calculate_psk_auth(struct state *st,
			      enum original_role role,
			      unsigned char *idhash,
			      pb_stream *a_pbs)
{
	unsigned int hash_len =  st->st_oakley.prf_hasher->hash_digest_len;
	unsigned char signed_octets[hash_len];

	if (!ikev2_calculate_psk_sighash(st, role, idhash,
					 st->st_firstpacket_me,
					 signed_octets))
		return FALSE;

	DBG(DBG_PRIVATE,
	    DBG_dump("PSK auth octets", signed_octets, hash_len ));

	if (!out_raw(signed_octets, hash_len, a_pbs, "PSK auth"))
		return FALSE;

	return TRUE;
}
Beispiel #7
0
/*
 * used by initiator to make chunk_t from ppk_id payload
 * for sending it in PPK_ID Notify Payload over the wire
 */
bool emit_unified_ppk_id(struct ppk_id_payload *payl, pb_stream *pbs)
{
	u_char type = PPK_ID_FIXED;
	return out_raw(&type, sizeof(type), pbs, "PPK_ID_FIXED") &&
		out_chunk(payl->ppk_id, pbs, "PPK_ID");
}
Beispiel #8
0
int main(int argc, char *argv[]) {
	// mallocated stuff
	float * wave_buffer;
	float * aa_buffer;
	float * work_buffer;
	float * frame_buffer;
	float * dft_bins;
	unsigned int * frequencies;
	unsigned int * volumes;
	unsigned char * out_buffer;
	
	unsigned char consolidate;
	unsigned long wave_size, work_size;
	unsigned int frame_size, frame_inc;
	unsigned int i;
	int ofs;
	unsigned long idx;
	
	unsigned long c, m, k, t, f;
	unsigned int kmax;
	float max_power;
	float in_r, sum_r, sum_i;
	float ratio;
	unsigned long frame_idx = 0, frames;
	char outfilepath[256];
	unsigned int ext;
	
	puts("PSGTalk 0.3 - furrtek 2017\n");
	
	// Overlap = 0
	//   Data: ######################## (24)
	// Frames: AAAAAAAA
	//                 BBBBBBBB
	//                         CCCCCCCC
	//  Count: 3
	// Length: 8 = 24 / 3 * (0 + 1)
	// Offset: 8 = Length * (1 - 0)
	
	// Overlap = 0.5
	//   Data: ######################## (24)
	// Frames: AAAAAAAAAAAA
	//               BBBBBBBBBBBB
	//                     CCCCCCCCCCCC
	//  Count: 3
	// Length: 12 = 24 / 3 * (0.5 + 1)
	// Offset: Length * (1 - 0.5)
	
	// Defaults
	overlap = 0.25;
	updates_per_frame = 2;
	psg_channels = 3;
	sim = 0;
	mode = MODE_VGM;
	fps = 60;
	freq_res = 64;
	
	if (parse_args(argc, argv))
		return 1;

	wave_size = load_wav(argv[argc - 1], &wave_buffer);
	if (!wave_size) {
		puts("Can't load wave file.\n");
		return 1;
	}
	
	// Anti-alias filtering
	aa_buffer = calloc(wave_size, sizeof(float));
	if (aa_buffer == NULL) {
		puts("Memory allocation failed\n");
		free(wave_buffer);
		return 1;
	}
	lowpass(wave_buffer, aa_buffer, 8192.0, samplerate_in, wave_size);
	
	// Decimate
	ratio = ((float)samplerate_in / 8192.0);
	work_size = (int)(wave_size / ratio);
	work_buffer = calloc(work_size, sizeof(float));
	if (work_buffer == NULL) {
		puts("Memory allocation failed\n");
		free(wave_buffer);
		free(aa_buffer);
		return 1;
	}
	
	for (i = 0; i < work_size; i++)
		work_buffer[i] = aa_buffer[(int)(i * ratio)];

	update_rate = fps * updates_per_frame;
	frame_size = (8192.0 * (overlap + 1.0)) / update_rate;
	frame_inc = (float)frame_size * (1.0 - overlap);
	m = 1;									// Discrimination between power peaks
	frames = work_size / frame_inc;			// Total number of frames
	freq_step = (8192 / freq_res) / 2;
	
	frame_buffer = calloc(frame_size, sizeof(float));
	dft_bins = calloc(freq_res, sizeof(float));
	frequencies = calloc(frames * psg_channels, sizeof(unsigned int));
	volumes = calloc(frames * psg_channels, sizeof(unsigned int));
	
	if ((dft_bins == NULL) || (frame_buffer == NULL) || (frequencies == NULL) || (volumes == NULL)) {
		puts("Memory allocation failed\n");
		return 1;
	}
	
	if (!make_LUTs(frame_size)) {
		puts("Table generation failed\n");
		return 1;
	}
	
	// Show recap
	printf("Frames: %lu\n", frames);
	printf("Overlap: %u%%\n", (unsigned int)(overlap * 100.0));
	printf("Samplerate: %luHz -> %uHz\n", samplerate_in, 8192);
	printf("Resolution: %uHz\n", freq_step);
	printf("Update rate: %u/frame (%uHz @ %ufps)\n", updates_per_frame, update_rate, fps);
	printf("PSG channels: %u\n", psg_channels);
	printf("Mode: %s\n", modestr[mode]);
	
	
	f = 0;
	do {
		// Copy frame
		memcpy(frame_buffer, &work_buffer[f], frame_size * sizeof(float));
		
		// Apply window
		for (t = 0; t < frame_size; t++)
			frame_buffer[t] *= window_lut[t];
		
		// Do DFT
    	for (k = 0; k < freq_res; k++) {		// For each output element
  	      	sum_r = 0;
  	      	sum_i = 0;
        	for (t = 0; t < frame_size; t++) {			// For each input element
            	c = ((32768 * t * k / 2) / frame_size) & 0x7FFF;
            	in_r = frame_buffer[t];
            	sum_r += (in_r * cos_lut[c]);
            	sum_i += (in_r * sin_lut[c]);
			}
            sum_r /= frame_size;
        	sum_i /= frame_size;
        
        	dft_bins[k] = sqrt((sum_i * sum_i) + (sum_r * sum_r));
    		//if (f == 0) printf("SAMP=%f POW=%f (%uHz)\n", frame_buffer[k], dft_bins[k], k * freq_step);
		}

		// Find highest peaks
		consolidate = 0;
		for (c = 0; c < psg_channels; c++) {
			idx = (frame_idx * psg_channels) + c;
			if (consolidate) {
				max_power -= 0.4;
	    		frequencies[idx] = frequencies[idx - 1];
	    		volumes[idx] = lintolog(max_power);
			} else {
				// Find highest power and its associated frequency (skip DC bin)
		    	max_power = 0;
		    	for (k = 1; k < (frame_size - 1); k++) {
					if (dft_bins[k] > max_power) {
						max_power = dft_bins[k];
						kmax = k;
					}
				}
				// Clear surrounding bins if needed
				for (t = 0; t < m; t++) {
					ofs = kmax - t - 1;
					if (ofs >= 0) dft_bins[ofs] = 0;
					ofs = kmax + t + 1;
					if (ofs < freq_res) dft_bins[ofs] = 0;	
				}
				
		    	frequencies[idx] = kmax;
		    	volumes[idx] = lintolog(max_power);
			}
			
			consolidate = (max_power >= 0.4) ? 1 : 0;
			
			if (frame_idx == 0) printf("C%lu=%uHz\n", c, kmax * freq_step);		// DEBUG
		}
        
    	frame_idx++;
    	f += frame_inc;
    
    	printf("\rComputing frame %lu/%lu.", frame_idx, frames);

	} while (f < (work_size - frame_size));
	
	puts(" Done.\n");
	
	// Generate output file
	strcpy(outfilepath, argv[argc - 1]);
	ext = strlen(outfilepath) - 3;
	if (mode == MODE_VGM) {
		outfilepath[ext++] = 'v';
		outfilepath[ext++] = 'g';
		outfilepath[ext] = 'm';
	} else {
		outfilepath[ext++] = 'b';
		outfilepath[ext++] = 'i';
		outfilepath[ext] = 'n';
	}


	FILE * fo = fopen(outfilepath, "wb");
	
	if (mode == MODE_RAW) {
		out_raw(&out_buffer, frequencies, volumes, frame_idx, freq_res);
	} else if (mode == MODE_VGM) {
		out_vgm(&out_buffer, frequencies, volumes, frame_idx);
	} else if (mode == MODE_NGP) {
		out_ngp(&out_buffer, frequencies, volumes, frame_idx);
	}

	fwrite(out_buffer, file_length, 1, fo);
	fclose(fo);

	free(out_buffer);
	
	puts("Output file written.");
	printf("Size: %lukB\n", file_length / 1024);

	// Generate simulation file if needed
	if (sim) {
		if (gen_sim(frame_size, frame_idx, psg_channels, frequencies, volumes))
			puts("\nSimulation file written.\n");
	}
	
	free(frequencies);
	free(volumes);
	free(frame_buffer);
	free(wave_buffer);
	free(work_buffer); 
	free(dft_bins);
	
    system("pause");
    //return 0;

	return 0;
}