⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nokia.c

📁 NOKIA手机开发包
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (sm_message_send(5 + n, 0x40, req, state)) return GN_ERR_NOTREADY;	return sm_block(0x40, data, state);}gn_error pnok_call_answer(gn_data *data, struct gn_statemachine *state){	unsigned char req[4] = {0x00, 0x01, 0x7c, 0x02};	gn_error err;	if (!data->call_info) return GN_ERR_INTERNALERROR;	if ((err = pnok_extended_cmds_enable(0x01, data, state)))		return err;	if (sm_message_send(4, 0x40, req, state)) return GN_ERR_NOTREADY;	return sm_block(0x40, data, state);}gn_error pnok_call_cancel(gn_data *data, struct gn_statemachine *state){	unsigned char req[4] = {0x00, 0x01, 0x7c, 0x03};	gn_error err;	if (!data->call_info) return GN_ERR_INTERNALERROR;	if ((err = pnok_extended_cmds_enable(0x01, data, state)))		return err;	if (sm_message_send(4, 0x40, req, state)) return GN_ERR_NOTREADY;	return sm_block(0x40, data, state);}gn_error pnok_netmonitor(gn_data *data, struct gn_statemachine *state){	unsigned char req[] = {0x00, 0x01, 0x7e, 0x00};	gn_error err;	if (!data->netmonitor) return GN_ERR_INTERNALERROR;	req[3] = data->netmonitor->field;	if ((err = pnok_extended_cmds_enable(0x01, data, state))) return err;	if (sm_message_send(4, 0x40, req, state)) return GN_ERR_NOTREADY;	return sm_block(0x40, data, state);}gn_error pnok_get_locks_info(gn_data *data, struct gn_statemachine *state){	unsigned char req[] = {0x00, 0x01, 0x8a, 0x00};	if (sm_message_send(4, 0x40, req, state)) return GN_ERR_NOTREADY;	return sm_block(0x40, data, state);}gn_error pnok_play_tone(gn_data *data, struct gn_statemachine *state){	unsigned char req[] = {0x00, 0x01, 0x8f, 0x00, 0x00, 0x00};	req[3] = data->tone->volume;	req[4] = data->tone->frequency / 256;	req[5] = data->tone->frequency % 256;	if (sm_message_send(6, 0x40, req, state)) return GN_ERR_NOTREADY;	return sm_block(0x40, data, state);}gn_error pnok_security_incoming(int messagetype, unsigned char *message, int length, gn_data *data, struct gn_statemachine *state){	char  tmp[24];	int i;	switch (message[2]) {	/* Enable extended commands */	case 0x64:		dprintf("Message: Extended commands enabled.\n");		break;	/* Call management (old style) */	case 0x7c:		switch (message[3]) {			case 0x01: dprintf("Message: CallMgmt (old): dial\n"); break;			case 0x02: dprintf("Message: CallMgmt (old): answer\n"); break;			case 0x03: dprintf("Message: CallMgmt (old): release\n"); break;			default: return GN_ERR_UNHANDLEDFRAME;		}		break;	/* Netmonitor */	case 0x7e:		switch (message[3]) {		case 0x00:			dprintf("Message: Netmonitor correctly set.\n");			break;		default:			dprintf("Message: Netmonitor menu %d received:\n", message[3]);			dprintf("%s\n", message + 4);			if (data->netmonitor)				snprintf(data->netmonitor->screen, sizeof(data->netmonitor->screen), "%s", message + 4);			break;		}		break;	/* Get (sim)lock info */	case 0x8a:		for (i = 0; i < 4; i++) {			memset(&data->locks_info[i], 0, sizeof(gn_locks_info));		}		data->locks_info[0].userlock = ((message[5] & 0x01) != 0);		data->locks_info[1].userlock = ((message[5] & 0x02) != 0);		data->locks_info[2].userlock = ((message[5] & 0x04) != 0);		data->locks_info[3].userlock = ((message[5] & 0x08) != 0);		data->locks_info[0].closed = ((message[6] & 0x01) != 0);		data->locks_info[1].closed = ((message[6] & 0x02) != 0);		data->locks_info[2].closed = ((message[6] & 0x04) != 0);		data->locks_info[3].closed = ((message[6] & 0x08) != 0);		bin2hex(tmp, message + 9, 12);		strncpy(data->locks_info[0].data, tmp, 5);		strncpy(data->locks_info[1].data, tmp + 16, 4);		strncpy(data->locks_info[2].data, tmp + 20, 4);		strncpy(data->locks_info[3].data, tmp + 5, 10);		data->locks_info[0].counter = message[21];		data->locks_info[1].counter = message[22];		data->locks_info[2].counter = message[23];		data->locks_info[3].counter = message[24];		break;	/* Play tone */	case 0x8f:		break;	default:		return GN_ERR_UNHANDLEDFRAME;	}	return GN_ERR_NONE;}gn_error pnok_ringtone_from_raw(gn_ringtone *ringtone, const unsigned char *raw, int rawlen){	int i, c, p, current;	int rcount, rstart;	int lastc, lastp;	gn_ringtone_note *note;	int notes[] = {0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12};	int dct4, base;	ringtone->tempo = 120;	dct4 = 0;	base = 114;recode:	ringtone->notes_count = 0;	rstart = -1;	rcount = 0;	lastc = -1;	lastp = 0;	for(i = 0; i < rawlen; ) {		current = i;		c = raw[i++];		if (c == 0x00) {			/* start? */			continue;		} else if (c == 0x06) {			/* repeat end */			if (rstart < 0) continue; /* FIXME: why not corrupted */			p = ringtone->notes_count - rstart;			if (ringtone->notes_count + rcount * p >= GN_RINGTONE_MAX_NOTES)				return GN_ERR_INVALIDSIZE;			while (rcount-- > 0) {				memcpy(ringtone->notes + ringtone->notes_count, ringtone->notes + rstart, p * sizeof(gn_ringtone_note));				ringtone->notes_count += p;			}			rstart = -1;			rcount = 0;			continue;		} else if (c == 0x07) {			/* unknown */			continue;		} else if (c == 0x09) {			/* unknown */			continue;		} else if (c == 0x0b) {			/* stop */			break;		} else if (c == 0x0c) {			/* unknown */			continue;		} else if (c == 0x0e) {			/* unknown */			continue;		}		if (i >= rawlen) goto corrupted;		p = raw[i++];		if (c == 0x04) {			/* unknown */		} else if (c == 0x02) {			/* unknown */		} else if (c == 0x05) {			/* begin repeat */			if (rstart >= 0) goto corrupted;			rstart = ringtone->notes_count;			rcount = p - 1;		} else if (c == 0x0a) {			/* vibra? */		} else if (c == 0x40) {			/* pause */			if (p == 0x01) {				/* skip normal inter note pause */				lastc = -1;				continue;			}			if (c == lastc) {				lastp += p;				p = lastp;			} else {				note = ringtone->notes + ringtone->notes_count++;				lastc = c;				lastp = p;			}			note->note = 255;			gn_ringtone_set_duration(ringtone, note - ringtone->notes, 8000 * p);		} else if (66 <= c && c <= 161) {			/* normal tone */			if (c == lastc) {				lastp += p;				p = lastp;			} else {				note = ringtone->notes + ringtone->notes_count++;				lastc = c;				lastp = p;			}			if (c < base) {				if (!dct4) {					dct4 = 1;					base = 90;					goto recode;				}				note->note = notes[(c - 66) % 12];			} else {				note->note = 14 * ((c - base) / 12) + notes[(c - base) % 12];			}			gn_ringtone_set_duration(ringtone, note - ringtone->notes, 8000 * p);		} else {			/* unknown messages */			goto corrupted;		}	}	/* check wheter the tempo selected correctly */	c = 0;	for (i = 0; i < ringtone->notes_count; i++)		if (ringtone->notes[i].note != 255 && ringtone->notes[i].duration > c)			c = ringtone->notes[i].duration;	if (ringtone->tempo < 250 && c < 32) {		/* there was no 1/8 */		ringtone->tempo = 250;		goto recode;	}	while (ringtone->notes_count > 0 && ringtone->notes[ringtone->notes_count - 1].note == 255)		ringtone->notes_count--;	return GN_ERR_NONE;corrupted:	dump(_("NOKIA RAW RINGTONE DECODING FAILED\nringtone:\n"));	for (i = 0; i < rawlen; i++) {		if (i % 16 == 0) {			if (i != 0) dump("\n");			dump("%04x", i);		}		dump(" %02x", raw[i]);	}	if (i % 16 != 0) dump("\n");	dump(_("offset: %04x\n"), current);	dump(_("Please read Docs/Bugs and send a bug report!\n"));	return GN_ERR_WRONGDATAFORMAT;}gn_error pnok_ringtone_to_raw(char *raw, int *rawlen, const gn_ringtone *ringtone, int dct4){	int i, c, p, l, freq, base;	int rleft, vtime, vstat;	const gn_ringtone_note *note;	char header[] = {0x00, 0x02, 0xfc, 0x0a, 0x01};	char tailer[] = {0x0a, 0x0a, 0x0a, 0xfe, 0x40, 0x20, 0x07, 0x0b, 0xff, 0xff, 0xff, 0xff};	char vibr_on[] = {0x0a, 0x01};	char vibr_off[] = {0x0a, 0xfe};	int notes[] = {0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 11};	rleft = *rawlen;	vtime = 0;	vstat = 1;	base = dct4 ? 90 : 114;	if (rleft < sizeof(header)) return GN_ERR_MEMORYFULL;	memcpy(raw, header, sizeof(header));	raw += sizeof(header);	rleft -= sizeof(header);	for (i = 0; i < ringtone->notes_count; i++) {		if (vtime >= 300) {			if (rleft < 2) return GN_ERR_MEMORYFULL;			memcpy(raw, vstat ? vibr_off : vibr_on, 2);			vtime = 0;			vstat = !vstat;			raw += 2;			rleft -= 2;		}		note = ringtone->notes + i;		gn_ringtone_get_tone(ringtone, i, &freq, &p);		p /= 8000;		vtime += p;		if (note->note == 0xff) {			c = 0x40;			p++;		} else {			c = 12 * (note->note / 14) + notes[note->note % 14] + base;		}		while (p > 1) {			if (rleft < 2) return GN_ERR_MEMORYFULL;			l = (p > 0xff) ? 0xff : p - 1;			*raw++ = c;			*raw++ = l;			p -= l;			rleft -= 2;		}		if (c != 0x40) {			if (rleft < 2) return GN_ERR_MEMORYFULL;			*raw++ = 0x40;			*raw++ = 1;			rleft -= 2;		}	}	if (rleft < sizeof(tailer)) return GN_ERR_MEMORYFULL;	memcpy(raw, tailer, sizeof(tailer));	rleft -= sizeof(tailer);	*rawlen = (*rawlen - rleft) & ~3;	return GN_ERR_NONE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -