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

📄 shell.c.svn-base

📁 Linux下gsm/gprs modem的看守程序。支持短信发送与接受。
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
		pending_responses --;		break;	case GSMD_VOICECALL_FWD_ERAS:		pending_responses --;		break;	default:		return -EINVAL;	}	return 0;}static const struct msghandler_s {	int type;	lgsm_msg_handler *fn;} msghandlers[] = {	{ GSMD_MSG_PASSTHROUGH,	pt_msghandler },	{ GSMD_MSG_PHONEBOOK,	pb_msghandler },	{ GSMD_MSG_SMS,		sms_msghandler },	{ GSMD_MSG_NETWORK,	net_msghandler },	{ GSMD_MSG_PHONE,	phone_msghandler },	{ GSMD_MSG_PIN,		pin_msghandler },	{ GSMD_MSG_VOICECALL,	call_msghandler },	{ 0, 0 }};static void shell_help(void){	printf( "\tA\tAnswer incoming call\n"		"\tD\tDial outgoing number\n"		"\tH\tHangup call\n"		"\tO\tAntenna Power On\n"		"\to\tAntenna Power Off\n"		"\tgos\tGet Antenna Status\n"		"\tV\tVibrator Enable (CVIB=1)\n"		"\tv\tVibrator Disable (CVIB=0)\n"	       	"\tM\tModem Power On\n"		"\tm\tModem Power Off\n"		"\tr\tRegister to network\n"		"\tR\tRegister to given operator (R=number)\n"		"\tU\tUnregister from netowrk\n"		"\tP\tPrint current operator\n"		"\tN\tPrint current operator in numeric\n"		"\tL\tList available operators\n"		"\tQ\tRead signal quality\n"		"\tnr\tQuery network registration\n"		"\tS\tSleep (S[=second], default 5)\n"		"\tT\tSend DTMF Tone\n"		"\tn\tPrint subscriber numbers\n"		"\tpd\tPB Delete (pb=index)\n"		"\tpr\tPB Read (pr=index)\n"		"\tprr\tPB Read Range (prr=index1,index2)\n"		"\tpf\tPB Find (pf=indtext)\n"		"\tpw\tPB Write (pw=index,number,text)\n"		"\tps\tPB Support\n"		"\tpm\tPB Memory\n"		"\tpp\tPB Set Memory (pp=storage)\n"		"\tsd\tSMS Delete (sd=index,delflg)\n"		"\tsl\tSMS List (sl=stat)\n"		"\tsr\tSMS Read (sr=index)\n"		"\tss\tSMS Send (ss=ask_ds,number,text|[\"text\"])\n"		"\tsw\tSMS Write (sw=stat,number,text)\n"		"\tsm\tSMS Storage stats\n"		"\tsM\tSMS Set preferred storage (sM=mem1,mem2,mem3)\n"		"\tsc\tSMS Show Service Centre\n"		"\tsC\tSMS Set Service Centre (sC=number)\n"		"\tgvm\tGet Voicemail number\n"		"\tsvm\tSet Voicemail number(svm=number)\n"		"\tim\tGet imsi\n"		"\tmf\tGet manufacturer\n"		"\tml\tGet model\n"		"\trv\tGet revision\n"		"\tsn\tGet serial number\n"		"\tcs\tGet Call status\n"		"\tgp\tGet PIN status\n"		"\tcbc\tGet Battery status\n"		"\tRh\tRelease all held calls (+CHLD=0)\n"		"\tUDUB\tUser Determined User Busy (+CHLD=0)\n"		"\tRa\tRelease all active calls (+CHLD=1)\n"		"\tRx\tRelease specific active call x (Rx=x)(+CHLD=1x)\n"		"\tHa\tHold all active calls and accept held or waiting call (+CHLD=2)\n"		"\tHx\tHold all active calls except call x (Hx=x)(+CHLD=2x)\n"		"\tMP\tAdd a held call to the conversation (+CHLD=3)\n"		"\tCFD\tDisable call forwarding (CFD=reason)\n"		"\tCFE\tEnable call forwarding (CFE=reason)\n"		"\tCFQ\tQuery the status of call forwarding (CFQ=reason)\n"		"\tCFR\tRegister call forwarding (CFR=reason,number)\n"		"\tCFe\tErase a record of call forwarding (CFe=reason)\n"		"\tq\tQuit\n"		);}int shell_main(struct lgsm_handle *lgsmh, int sync){	int rc;	char buf[STDIN_BUF_SIZE+1];	fd_set readset;	char *ptr, *fcomma, *lcomma;	int gsm_fd = lgsm_fd(lgsmh);	const struct msghandler_s *hndl;	for (hndl = msghandlers; hndl->fn; hndl ++)		lgsm_register_handler(lgsmh, hndl->type, hndl->fn);	fcntl(0, F_SETFD, O_NONBLOCK);	fcntl(gsm_fd, F_SETFD, O_NONBLOCK);	FD_ZERO(&readset);	printf("# ");	while (1) {		fd_set readset;		FD_SET(0, &readset);		FD_SET(gsm_fd, &readset);		rc = select(gsm_fd+1, &readset, NULL, NULL, NULL);		if (rc <= 0)			break;		if (FD_ISSET(gsm_fd, &readset)) {			/* we've received something on the gsmd socket, pass it			 * on to the library */			rc = read(gsm_fd, buf, sizeof(buf));			if (rc <= 0) {				printf("ERROR reading from gsm_fd\n");				break;			}			rc = lgsm_handle_packet(lgsmh, buf, rc);			if (rc < 0)				printf("ERROR processing packet: %d(%s)\n", rc, strerror(-rc));		}		if (FD_ISSET(0, &readset)) {			/* we've received something on stdin.  */			printf("# ");			rc = fscanf(stdin, "%s", buf);			if (rc == EOF) {				printf("EOF\n");				return -1;			}			if (rc <= 0) {				printf("NULL\n");				continue;			}			if (!strcmp(buf, "h")) {				shell_help();			} else if (!strcmp(buf, "?")) {				shell_help();			} else if (!strcmp(buf, "H")) {				printf("Hangup\n");				lgsm_voice_hangup(lgsmh);			} else if (buf[0] == 'D') {				struct lgsm_addr addr;				if (strlen(buf) < 2)					continue;				printf("Dial %s\n", buf+1);				addr.type = 129;				strncpy(addr.addr, buf+1, sizeof(addr.addr)-1);				addr.addr[sizeof(addr.addr)-1] = '\0';				lgsm_voice_out_init(lgsmh, &addr);			} else if (!strcmp(buf, "A")) {				printf("Answer\n");				lgsm_voice_in_accept(lgsmh);			} else if (!strcmp(buf, "O")) {				printf("Power-On\n");				lgsm_phone_power(lgsmh, 1);			} else if (!strcmp(buf, "o")) {				printf("Power-Off\n");				lgsm_phone_power(lgsmh, 0);			} else if (!strcmp(buf, "gos")) {				printf("Get Antenna status\n");				lgsm_get_power_status(lgsmh);			} else if (!strcmp(buf, "V")) {				printf("Vibrator-Enable\n");				lgsm_phone_vibrator(lgsmh, 1);			} else if (!strcmp(buf, "v")) {				printf("Vibrator-Disable\n");				lgsm_phone_vibrator(lgsmh, 0);			} else if (!strcmp(buf, "r")) {				printf("Register\n");				lgsm_netreg_register(lgsmh, "\0     ");			} else if (!strcmp(buf,"R")) {				printf("Register to operator\n");				ptr = strchr(buf, '=');				if (!ptr || strlen(ptr) < 6)					printf("No.\n");				else					lgsm_netreg_register(lgsmh, ptr + 1);			} else if (!strcmp(buf, "U")) {				printf("Unregister\n");				lgsm_netreg_deregister(lgsmh);			} else if (!strcmp(buf, "P")) {				printf("Read current opername\n");				lgsm_oper_get(lgsmh);				pending_responses ++;			} else if (!strcmp(buf, "N")) {				printf("Read current opername in numeric format\n");				lgsm_oper_n_get(lgsmh);				pending_responses ++;			} else if (!strcmp(buf, "L")) {				printf("List operators\n");				lgsm_opers_get(lgsmh);				pending_responses ++;			} else if (!strcmp(buf, "Q")) {				printf("Signal strength\n");				lgsm_signal_quality(lgsmh);				pending_responses ++;			} else if (!strcmp(buf, "nr")) {				printf("Query network registration\n");				lgsm_netreg_query(lgsmh);				pending_responses ++;			} else if (!strcmp(buf, "q")) {				exit(0);			} else if (buf[0] == 'S' ) {				if(!strchr(buf,'=') || atoi((strchr(buf,'=')+1)) < 0) {					printf("Sleep 5 secs\n");					sleep(5);				}else {					printf("Sleep %d secs\n",atoi(strchr(buf,'=')+1));					sleep(atoi(strchr(buf,'=')+1));				}			} else if (buf[0] == 'T') {				if (strlen(buf) < 2)					continue;				printf("DTMF: %c\n", buf[1]);				lgsm_voice_dtmf(lgsmh, buf[1]);			} else if ( !strncmp(buf, "pd", 2)) {				printf("Delete Phonebook Entry\n");							ptr = strchr(buf, '=');				lgsm_pb_del_entry(lgsmh, atoi(ptr+1));			} else if ( !strncmp(buf, "prr", 3)) {					printf("Read Phonebook Entries\n");				struct lgsm_phonebook_readrg pb_readrg;				ptr = strchr(buf, '=');				pb_readrg.index1 = atoi(ptr+1);								ptr = strchr(buf, ',');				pb_readrg.index2 = atoi(ptr+1);				lgsm_pb_read_entries(lgsmh, &pb_readrg);				pending_responses ++;			} else if ( !strncmp(buf, "pr", 2)) {				ptr = strchr(buf, '=');				lgsm_pb_read_entry(lgsmh, atoi(ptr+1));			} else if ( !strncmp(buf, "pf", 2)) {				printf("Find Phonebook Entry\n");				struct lgsm_phonebook_find pb_find;				ptr = strchr(buf, '=');				strncpy(pb_find.findtext,						ptr + 1,						sizeof(pb_find.findtext) - 1);				pb_find.findtext[strlen(ptr+1)] = '\0';								lgsm_pb_find_entry(lgsmh, &pb_find);				pending_responses ++;			} else if ( !strncmp(buf, "pw", 2)) {				printf("Write Phonebook Entry\n");				struct lgsm_phonebook pb;				ptr = strchr(buf, '=');				pb.index = atoi(ptr+1);				fcomma = strchr(buf, ',');				lcomma = strchr(fcomma+1, ',');				strncpy(pb.numb, fcomma + 1, (lcomma - fcomma - 1));				pb.numb[(lcomma - fcomma - 1)] = '\0';				if ('+' == pb.numb[0])					pb.type = LGSM_PB_ATYPE_INTL;				else 					pb.type = LGSM_PB_ATYPE_OTHE;							strncpy(pb.text, lcomma + 1, strlen(lcomma + 1));				pb.text[strlen(lcomma + 1)] = '\0';				lgsm_pb_write_entry(lgsmh, &pb);			} else if ( !strncmp(buf, "pm", 2)) {				lgsm_pb_list_storage(lgsmh);			} else if ( !strncmp(buf, "pp", 2)) {				char storage[3];				ptr = strchr(buf, '=');				strncpy(storage, (ptr+1), 2);				lgsm_pb_set_storage(lgsmh, storage);			} else if ( !strncmp(buf, "ps", 2)) {					printf("Get Phonebook Support\n");				lgsm_pb_get_support(lgsmh);				pending_responses ++;			} else if ( !strncmp(buf, "sd", 2)) {						printf("Delete SMS\n");							struct lgsm_sms_delete sms_del;				ptr = strchr(buf, '=');				sms_del.index = atoi(ptr+1);				ptr = strchr(buf, ',');				sms_del.delflg = atoi(ptr+1);								lgsm_sms_delete(lgsmh, &sms_del);				pending_responses ++;			} else if ( !strncmp(buf, "sl", 2)) {				printf("List SMS\n");				ptr = strchr(buf, '=');				lgsm_sms_list(lgsmh, atoi(ptr+1));				pending_responses ++;			} else if ( !strncmp(buf, "sr", 2)) {				printf("Read SMS\n");				ptr = strchr(buf, '=');				lgsm_sms_read(lgsmh, atoi(ptr+1));				pending_responses ++;			} else if ( !strncmp(buf, "ss", 2)) {				struct lgsm_sms sms;				ptr = strchr(buf, '=');				sms.ask_ds = atoi(ptr+1);				fcomma = strchr(buf, ',');				lcomma = strchr(fcomma+1, ',');				strncpy(sms.addr, fcomma+1, lcomma-fcomma-1);				sms.addr[lcomma-fcomma-1] = '\0';				/* todo define \" to allow " in text */				if (lcomma[1]=='"' && !strchr(lcomma+2, '"')) {					/* read until closing '"' */					rc = fscanf(stdin, "%[^\"]\"", lcomma+strlen(lcomma));					if (rc == EOF) {						printf("EOF\n");						return -1;					}					/* remove brackets */					lcomma++;					lcomma[strlen(lcomma)] = '\0';				}				printf("Send SMS\n");				packing_7bit_character(lcomma+1, &sms);				lgsm_sms_send(lgsmh, &sms);				pending_responses ++;			} else if ( !strncmp(buf, "sw", 2)) {					printf("Write SMS\n");								struct lgsm_sms_write sms_write;				ptr = strchr(buf, '=');				sms_write.stat = atoi(ptr+1);				fcomma = strchr(buf, ',');				lcomma = strchr(fcomma+1, ',');				strncpy(sms_write.sms.addr,						fcomma+1, lcomma-fcomma-1);				sms_write.sms.addr[lcomma-fcomma-1] = '\0';				packing_7bit_character(						lcomma+1, &sms_write.sms);				sms_write.sms.ask_ds = 0;				lgsm_sms_write(lgsmh, &sms_write);				pending_responses ++;			} else if (!strncmp(buf, "sm", 2)) {				printf("Get SMS storage preferences\n");				lgsm_sms_get_storage(lgsmh);				pending_responses ++;			} else if (!strncmp(buf, "sM", 2)) {				int mem[3];				printf("Set SMS storage preferences\n");				if (sscanf(buf, "sM=%i,%i,%i", mem, mem + 1,							mem + 2) < 3)					printf("No.\n");				else					lgsm_sms_set_storage(lgsmh, mem[0],							mem[1], mem[2]);			} else if (!strncmp(buf, "sc", 2)) {				printf("Get the default SMSC\n");				lgsm_sms_get_smsc(lgsmh);				pending_responses ++;			} else if (!strncmp(buf, "sC", 2)) {				printf("Set the default SMSC\n");				ptr = strchr(buf, '=');				if (!ptr || strlen(ptr) < 6)					printf("No.\n");				else					lgsm_sms_set_smsc(lgsmh, ptr + 1);			} else if (!strcmp(buf, "n")) {				lgsm_get_subscriber_num(lgsmh);				pending_responses ++;			} else if ( !strncmp(buf, "gvm", 3)) {				printf("Get Voicemail Number\n");				lgsm_voicemail_get(lgsmh);				pending_responses ++;			} else if ( !strncmp(buf, "svm", 3)) {				printf("Set Voicemail Number\n");				ptr = strchr(buf, '=');				if (!ptr || strlen(ptr) < 3)					printf("No.\n");				else					lgsm_voicemail_set(lgsmh, ptr + 1);				pending_responses ++;			} else if (!strncmp(buf, "im", 2)) {				printf("Get imsi\n");				lgsm_get_imsi(lgsmh);				pending_responses ++;			} else if (!strncmp(buf, "mf", 2)) {				printf("Get manufacturer\n");				lgsm_get_manufacturer(lgsmh);				pending_responses ++;			} else if (!strncmp(buf, "ml", 2)) {				printf("Get model\n");				lgsm_get_model(lgsmh);				pending_responses ++;			} else if (!strncmp(buf, "rv", 2)) {				printf("Get revision\n");				lgsm_get_revision(lgsmh);				pending_responses ++;			} else if (!strncmp(buf, "sn", 2)) {				printf("Get serial number\n");				lgsm_get_serial(lgsmh);				pending_responses ++;			} else if ( strlen(buf)==1 && !strncmp(buf, "M", 1)) {				printf("Modem Power On\n");				lgsm_modem_power(lgsmh, 1);				pending_responses ++;			} else if (!strncmp(buf, "m", 1)) {				printf("Modem Power Off\n");				lgsm_modem_power(lgsmh, 0);				pending_responses ++;			} else if ( !strncmp(buf, "cs", 2)) {				printf("List current call status\n");				lgsm_voice_get_status(lgsmh);				pending_responses ++;			} else if ( !strncmp(buf, "gp", 2)) {				printf("Get PIN status\n");				lgsm_pin_status(lgsmh);				pending_responses ++;			} else if ( !strncmp(buf, "Rh", 2)) {				struct lgsm_voicecall_ctrl ctrl;					ctrl.proc = LGSM_VOICECALL_CTRL_R_HLDS; 				printf("Release all held calls\n");				lgsm_voice_ctrl(lgsmh, &ctrl);				pending_responses ++;			} else if ( !strncmp(buf, "UDUB", 4)) {				struct lgsm_voicecall_ctrl ctrl;					ctrl.proc = LGSM_VOICECALL_CTRL_UDUB; 				printf("User Determined User Busy\n");				lgsm_voice_ctrl(lgsmh, &ctrl);				pending_responses ++;			} else if ( !strncmp(buf, "Ra", 2)) {				struct lgsm_voicecall_ctrl ctrl;					ctrl.proc = LGSM_VOICECALL_CTRL_R_ACTS_A_HLD_WAIT; 				printf("Release all active calls\n");				lgsm_voice_ctrl(lgsmh, &ctrl);				pending_responses ++;			} else if ( !strncmp(buf, "Rx", 2)) {				struct lgsm_voicecall_ctrl ctrl;					ctrl.proc = LGSM_VOICECALL_CTRL_R_ACT_X; 				printf("Release specific active call x\n");				ptr = strchr(buf, '=');				ctrl.idx = atoi(ptr+1);				lgsm_voice_ctrl(lgsmh, &ctrl);				pending_responses ++;			} else if ( !strncmp(buf, "Ha", 2)) {				struct lgsm_voicecall_ctrl ctrl;					ctrl.proc = LGSM_VOICECALL_CTRL_H_ACTS_A_HLD_WAIT; 				printf("Hold all active calls and accept held or waiting"				        " call\n");				lgsm_voice_ctrl(lgsmh, &ctrl);				pending_responses ++;			} else if ( !strncmp(buf, "Hx", 2)) {				struct lgsm_voicecall_ctrl ctrl;					ctrl.proc = LGSM_VOICECALL_CTRL_H_ACTS_EXCEPT_X; 				printf("Hold all active calls except call x\n");				ptr = strchr(buf, '=');				ctrl.idx = atoi(ptr+1);				lgsm_voice_ctrl(lgsmh, &ctrl);				pending_responses ++;			} else if ( !strncmp(buf, "MP", 2)) {				struct lgsm_voicecall_ctrl ctrl;				ctrl.proc = LGSM_VOICECALL_CTRL_M_HELD; 				printf("Add a held call to the conversation\n");				lgsm_voice_ctrl(lgsmh, &ctrl);				pending_responses ++;			} else if ( !strncmp(buf, "CFD", 3)) {				printf("Disable call forwarding\n");				ptr = strchr(buf, '=');				lgsm_voice_fwd_disable(lgsmh, atoi(ptr+1));				pending_responses ++;			}else if ( !strncmp(buf, "CFE", 3)) {				printf("Enable call forwarding\n");				ptr = strchr(buf, '=');				lgsm_voice_fwd_enable(lgsmh, atoi(ptr+1));				pending_responses ++;			}else if ( !strncmp(buf, "CFQ", 3)) {				printf("Query the status of call forwarding\n");				ptr = strchr(buf, '=');				lgsm_voice_fwd_stat(lgsmh, atoi(ptr+1));				pending_responses ++;			}else if ( !strncmp(buf, "CFR", 3)) {				struct lgsm_voicecall_fwd_reg lvfr;				printf("Register call forwarding\n");				ptr = strchr(buf, '=');				lvfr.reason = atoi(ptr+1);				ptr = strchr(buf, ',');				strcpy(lvfr.number.addr, ptr+1);				lgsm_voice_fwd_reg(lgsmh, &lvfr);				pending_responses ++;			}else if ( !strncmp(buf, "CFe", 3)) {				printf("Erase a record of call forwarding\n");				ptr = strchr(buf, '=');				lgsm_voice_fwd_erase(lgsmh, atoi(ptr+1));				pending_responses ++;			}else if ( !strncmp(buf, "cbc", 3)) {				printf("Battery Connection status and Battery Charge Level\n");				lgsm_get_battery(lgsmh);				pending_responses++;			}else {				printf("Unknown command `%s'\n", buf);			}		}		fflush(stdout);	}	return 0;}

⌨️ 快捷键说明

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