Пример #1
0
static void hfp_current_operator(struct ofono_netreg *netreg,
				ofono_netreg_operator_cb_t cb, void *data)
{
	struct netreg_data *nd = ofono_netreg_get_data(netreg);
	struct cb_data *cbd = cb_data_new(cb, data);
	gboolean ok;

	if (!cbd)
		goto error;

	cbd->user = netreg;

	ok = g_at_chat_send(nd->chat, "AT+COPS=3,0", NULL,
			NULL, cbd, NULL);

	if (ok)
		ok = g_at_chat_send(nd->chat, "AT+COPS?", cops_prefix,
				cops_cb, cbd, g_free);

	if (ok)
		return;

error:
	CALLBACK_WITH_FAILURE(cb, NULL, data);
}
Пример #2
0
static int he910_enable(struct ofono_modem *modem)
{
	struct he910_data *data = ofono_modem_get_data(modem);

	DBG("%p", modem);

	data->modem = open_device(modem, "Modem", "Modem: ");
	if (data->modem == NULL)
		return -EINVAL;

	data->chat = open_device(modem, "Aux", "Aux: ");
	if (data->chat == NULL) {
		g_at_chat_unref(data->modem);
		data->modem = NULL;
		return -EIO;
	}

	g_at_chat_set_slave(data->modem, data->chat);

	/*
	 * Disable command echo and
	 * enable the Extended Error Result Codes
	 */
	g_at_chat_send(data->chat, "ATE0 +CMEE=1", none_prefix,
				NULL, NULL, NULL);

	/* Set phone functionality */
	g_at_chat_send(data->chat, "AT+CFUN=1", none_prefix,
				cfun_enable_cb, modem, NULL);

	return -EINPROGRESS;
}
Пример #3
0
static void cfun_enable_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct ofono_modem *modem = user_data;
	struct telit_data *data = ofono_modem_get_data(modem);

	DBG("%p", modem);

	if (!ok) {
		g_at_chat_unref(data->chat);
		data->chat = NULL;
		ofono_modem_set_powered(modem, FALSE);
		return;
	}

	ofono_modem_set_powered(modem, TRUE);

	/* Enable sim state notification */
	g_at_chat_send(data->chat, "AT#QSS=1", none_prefix, NULL, NULL, NULL);

	/* Follow sim state */
	g_at_chat_register(data->chat, "#QSS:", telit_qss_notify,
				FALSE, modem, NULL);

	/* Query current sim state */
	g_at_chat_send(data->chat, "AT#QSS?", qss_prefix,
				telit_qss_cb, modem, NULL);
}
Пример #4
0
static void at_gprs_registration_status(struct ofono_gprs *gprs,
					ofono_gprs_status_cb_t cb,
					void *data)
{
	struct gprs_data *gd = ofono_gprs_get_data(gprs);
	struct cb_data *cbd = cb_data_new(cb, data);

	if (!cbd)
		goto error;

	cbd->user = gd;

	switch (gd->vendor) {
	case OFONO_VENDOR_NOVATEL:
		/*
		 * Send $CNTI=0 to find out the current tech, it will be
		 * intercepted in nw_cnti_notify in network registration
		 */
		g_at_chat_send(gd->chat, "AT$CNTI=0", none_prefix,
				NULL, NULL, NULL);
		break;
	}

	if (g_at_chat_send(gd->chat, "AT+CGREG?", cgreg_prefix,
				at_cgreg_cb, cbd, g_free) > 0)
		return;

error:
	if (cbd)
		g_free(cbd);

	CALLBACK_WITH_FAILURE(cb, -1, data);
}
Пример #5
0
static void at_signal_strength(struct ofono_netreg *netreg,
				ofono_netreg_strength_cb_t cb, void *data)
{
	struct netreg_data *nd = ofono_netreg_get_data(netreg);
	struct cb_data *cbd = cb_data_new(cb, data);

	cbd->user = nd;

	/*
	 * If we defaulted to using CIND, then keep using it,
	 * otherwise fall back to CSQ
	 */
	if (nd->signal_index > 0) {
		if (g_at_chat_send(nd->chat, "AT+CIND?", cind_prefix,
					cind_cb, cbd, g_free) > 0)
			return;
	} else {
		if (g_at_chat_send(nd->chat, "AT+CSQ", csq_prefix,
				csq_cb, cbd, g_free) > 0)
			return;
	}

	g_free(cbd);

	CALLBACK_WITH_FAILURE(cb, -1, data);
}
Пример #6
0
static void at_current_operator(struct ofono_netreg *netreg,
				ofono_netreg_operator_cb_t cb, void *data)
{
	struct netreg_data *nd = ofono_netreg_get_data(netreg);
	struct cb_data *cbd = cb_data_new(cb, data);
	gboolean ok;

	cbd->user = netreg;

	/* Nokia modems have a broken return value for the string
	 * returned for the numeric value. It misses a " at the end.
	 * Trying to read this will stall the parser. So skip it. */
	if (nd->vendor == OFONO_VENDOR_NOKIA) {
		ok = g_at_chat_send(nd->chat, "AT+COPS=3,0", none_prefix,
							NULL, NULL, NULL);

		if (ok)
			ok = g_at_chat_send(nd->chat, "AT+COPS?", cops_prefix,
							cops_cb, cbd, NULL);
	} else {
		ok = g_at_chat_send(nd->chat, "AT+COPS=3,2", none_prefix,
							NULL, NULL, NULL);

		if (ok)
			ok = g_at_chat_send(nd->chat, "AT+COPS?", cops_prefix,
						cops_numeric_cb, cbd, NULL);
	}

	if (ok)
		return;

	g_free(cbd);

	CALLBACK_WITH_FAILURE(cb, NULL, data);
}
Пример #7
0
static void at_cmgs(struct ofono_sms *sms, unsigned char *pdu, int pdu_len,
			int tpdu_len, int mms, ofono_sms_submit_cb_t cb,
			void *user_data)
{
	struct sms_data *data = ofono_sms_get_data(sms);
	struct cb_data *cbd = cb_data_new(cb, user_data);
	char buf[512];
	int len;

	if (mms) {
		snprintf(buf, sizeof(buf), "AT+CMMS=%d", mms);
		g_at_chat_send(data->chat, buf, none_prefix,
				NULL, NULL, NULL);
	}

	len = snprintf(buf, sizeof(buf), "AT+CMGS=%d\r", tpdu_len);
	encode_hex_own_buf(pdu, pdu_len, 0, buf+len);

	if (g_at_chat_send(data->chat, buf, cmgs_prefix,
				at_cmgs_cb, cbd, g_free) > 0)
		return;

	g_free(cbd);

	CALLBACK_WITH_FAILURE(cb, -1, user_data);
}
Пример #8
0
static int telit_sap_enable(struct ofono_modem *modem,
					struct ofono_modem *sap_modem,
					int bt_fd)
{
	struct telit_data *data = ofono_modem_get_data(modem);
	int fd;

	DBG("%p", modem);

	fd = telit_sap_open();
	if (fd < 0)
		goto error;

	data->hw_io = g_io_channel_unix_new(fd);
	if (data->hw_io == NULL) {
		close(fd);
		goto error;
	}

	g_io_channel_set_encoding(data->hw_io, NULL, NULL);
	g_io_channel_set_buffered(data->hw_io, FALSE);
	g_io_channel_set_close_on_unref(data->hw_io, TRUE);

	data->bt_io = g_io_channel_unix_new(bt_fd);
	if (data->bt_io == NULL)
		goto error;

	g_io_channel_set_encoding(data->bt_io, NULL, NULL);
	g_io_channel_set_buffered(data->bt_io, FALSE);
	g_io_channel_set_close_on_unref(data->bt_io, TRUE);

	data->hw_watch = g_io_add_watch_full(data->hw_io, G_PRIORITY_DEFAULT,
				G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN,
				hw_event_cb, modem, hw_watch_remove);

	data->bt_watch = g_io_add_watch_full(data->bt_io, G_PRIORITY_DEFAULT,
				G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN,
				bt_event_cb, modem, bt_watch_remove);

	data->sap_modem = sap_modem;

	g_at_chat_register(data->chat, "#RSEN:", telit_rsen_notify,
				FALSE, modem, NULL);

	g_at_chat_send(data->chat, "AT#NOPT=0", NULL, NULL, NULL, NULL);

	/* Set SAP functionality */
	g_at_chat_send(data->chat, "AT#RSEN=1,1,0,2,0", rsen_prefix,
				rsen_enable_cb, modem, NULL);

	return -EINPROGRESS;

error:
	shutdown(bt_fd, SHUT_RDWR);
	close(bt_fd);

	sap_close_io(modem);
	return -EINVAL;
}
Пример #9
0
static int mbm_enable(struct connman_device *device)
{
	struct mbm_data *data = connman_device_get_data(device);
	const char *devnode;
	GIOChannel *channel;
	struct termios ti;
	int fd, index;

	_DBG_MBM("device %p", device);

	devnode = connman_device_get_control(device);
	if (devnode == NULL)
		return -EIO;

	fd = open(devnode, O_RDWR | O_NOCTTY);
	if (fd < 0)
		return -ENODEV;

	tcflush(fd, TCIOFLUSH);

	/* Switch TTY to raw mode */
	memset(&ti, 0, sizeof(ti));
	cfmakeraw(&ti);

	tcsetattr(fd, TCSANOW, &ti);

	channel = g_io_channel_unix_new(fd);
	if (channel == NULL) {
		close(fd);
		return -ENOMEM;
	}

	data->chat = g_at_chat_new(channel, 0);
	if (data->chat == NULL)
		return -EIO;

	g_io_channel_unref(channel);

	g_at_chat_register(data->chat, "*EMRDY:", notify_callback,
							FALSE, NULL, NULL);
	g_at_chat_register(data->chat, "*EMWI:", notify_callback,
							FALSE, NULL, NULL);
	g_at_chat_register(data->chat, "+PACSP", notify_callback,
							FALSE, NULL, NULL);

	index = connman_device_get_index(device);
	connman_inet_ifup(index);

	g_at_chat_send(data->chat, "AT&F E0 V1 X4 &C1 +CMEE=1", NULL,
					generic_callback, NULL, NULL);

	g_at_chat_send(data->chat, "AT+CFUN?", cfun_prefix,
					cfun_callback, device, NULL);
	g_at_chat_send(data->chat, "AT+CFUN=1", NULL,
					cfun_callback, device, NULL);

	return -EINPROGRESS;
}
Пример #10
0
static void at_gprs_activate_primary(struct ofono_gprs_context *gc,
                                     const struct ofono_gprs_primary_context *ctx,
                                     ofono_gprs_context_cb_t cb, void *data)
{
    struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
    char buf[OFONO_GPRS_MAX_APN_LENGTH + 128];
    int len;

    /* IPv6 support not implemented */
    if (ctx->proto != OFONO_GPRS_PROTO_IP)
        goto error;

    DBG("cid %u", ctx->cid);

    gcd->active_context = ctx->cid;
    gcd->cb = cb;
    gcd->cb_data = data;
    memcpy(gcd->username, ctx->username, sizeof(ctx->username));
    memcpy(gcd->password, ctx->password, sizeof(ctx->password));

    gcd->state = STATE_ENABLING;

    if (gcd->vendor == OFONO_VENDOR_ZTE) {
        GAtChat *chat = g_at_chat_get_slave(gcd->chat);

        /*
         * The modem port of ZTE devices with certain firmware
         * versions ends up getting suspended. It will no longer
         * signal POLLOUT and becomes pretty unresponsive.
         *
         * To wake up the modem port, the only reliable method
         * found so far is AT+ZOPRT power mode command. It is
         * enough to ask for the current mode and the modem
         * port wakes up and accepts commands again.
         *
         * And since the modem port is suspended, this command
         * needs to be send on the control port of course.
         *
         */
        g_at_chat_send(chat, "AT+ZOPRT?", none_prefix,
                       NULL, NULL, NULL);
    }

    len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IP\"", ctx->cid);

    if (ctx->apn)
        snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
                 ctx->apn);

    if (g_at_chat_send(gcd->chat, buf, none_prefix,
                       at_cgdcont_cb, gc, NULL) > 0)
        return;

error:
    CALLBACK_WITH_FAILURE(cb, data);
}
Пример #11
0
static void at_cgreg_test_cb(gboolean ok, GAtResult *result,
				gpointer user_data)
{
	struct ofono_gprs *gprs = user_data;
	struct gprs_data *gd = ofono_gprs_get_data(gprs);
	gint range[2];
	GAtResultIter iter;
	int cgreg1 = 0;
	int cgreg2 = 0;
	const char *cmd;

	if (!ok)
		goto error;

	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "+CGREG:"))
		goto error;

	if (!g_at_result_iter_open_list(&iter))
		goto error;

	while (g_at_result_iter_next_range(&iter, &range[0], &range[1])) {
		if (1 >= range[0] && 1 <= range[1])
			cgreg1 = 1;
		if (2 >= range[0] && 2 <= range[1])
			cgreg2 = 1;
	}

	g_at_result_iter_close_list(&iter);

	if (cgreg2)
		cmd = "AT+CGREG=2";
	else if (cgreg1)
		cmd = "AT+CGREG=1";
	else
		goto error;

	g_at_chat_send(gd->chat, cmd, none_prefix, NULL, NULL, NULL);
	g_at_chat_send(gd->chat, "AT+CGAUTO=0", none_prefix, NULL, NULL, NULL);

	/* ST-E modem does not support AT+CGEREP = 2,1 */
	if (gd->vendor == OFONO_VENDOR_STE)
		g_at_chat_send(gd->chat, "AT+CGEREP=1,0", none_prefix,
			gprs_initialized, gprs, NULL);
	else
		g_at_chat_send(gd->chat, "AT+CGEREP=2,1", none_prefix,
			gprs_initialized, gprs, NULL);
	return;

error:
	ofono_info("GPRS not supported on this device");
	ofono_gprs_remove(gprs);
}
Пример #12
0
static int ifx_enable(struct ofono_modem *modem)
{
	struct ifx_data *data = ofono_modem_get_data(modem);
	const char *device, *ldisc;
	GAtSyntax *syntax;
	GAtChat *chat;

	DBG("%p", modem);

	device = ofono_modem_get_string(modem, "Device");
	if (device == NULL)
		return -EINVAL;

	DBG("%s", device);

	ldisc = ofono_modem_get_string(modem, "LineDiscipline");
	if (ldisc != NULL) {
		data->mux_ldisc = atoi(ldisc);
		ofono_info("Using multiplexer line discipline %d",
							data->mux_ldisc);
	}

	data->device = g_at_tty_open(device, NULL);
	if (data->device == NULL)
		return -EIO;

	syntax = g_at_syntax_new_gsmv1();
	chat = g_at_chat_new(data->device, syntax);
	g_at_syntax_unref(syntax);

	if (chat == NULL) {
		g_io_channel_unref(data->device);
		return -EIO;
	}

	if (getenv("OFONO_AT_DEBUG"))
		g_at_chat_set_debug(chat, ifx_debug, "Master: ");

	g_at_chat_send(chat, "ATE0 +CMEE=1", NULL,
					NULL, NULL, NULL);

	/* Enable multiplexer */
	data->frame_size = 1509;

	g_at_chat_send(chat, "AT+CMUX=0,0,,1509,10,3,30,,", NULL,
					mux_setup_cb, modem, NULL);

	data->mux_init_timeout = g_timeout_add_seconds(5, mux_timeout_cb,
								modem);

	data->dlcs[AUX_DLC] = chat;

	return -EINPROGRESS;
}
Пример #13
0
static void cops_numeric_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	struct netreg_data *nd = ofono_netreg_get_data(cbd->user);
	ofono_netreg_operator_cb_t cb = cbd->cb;
	GAtResultIter iter;
	const char *str;
	int format;
	int len;
	struct ofono_error error;

	decode_at_error(&error, g_at_result_final_response(result));

	if (!ok)
		goto error;

	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "+COPS:"))
		goto error;

	g_at_result_iter_skip_next(&iter);

	ok = g_at_result_iter_next_number(&iter, &format);

	if (ok == FALSE || format != 2)
		goto error;

	if (g_at_result_iter_next_string(&iter, &str) == FALSE)
		goto error;

	len = strspn(str, "0123456789");

	if (len != 5 && len != 6)
		goto error;

	extract_mcc_mnc(str, nd->mcc, nd->mnc);

	DBG("Cops numeric got mcc: %s, mnc: %s", nd->mcc, nd->mnc);

	ok = g_at_chat_send(nd->chat, "AT+COPS=3,0", none_prefix,
					NULL, NULL, NULL);

	if (ok)
		ok = g_at_chat_send(nd->chat, "AT+COPS?", cops_prefix,
					cops_cb, cbd, NULL);

	if (ok)
		return;

error:
	cb(&error, NULL, cbd->data);
	g_free(cbd);
}
Пример #14
0
static void at_registration_status(struct ofono_netreg *netreg,
					ofono_netreg_status_cb_t cb,
					void *data)
{
	struct netreg_data *nd = ofono_netreg_get_data(netreg);
	struct cb_data *cbd = cb_data_new(cb, data);

	cbd->user = nd;

	switch (nd->vendor) {
	case OFONO_VENDOR_MBM:
		/*
		 * Send *ERINFO to find out the current tech, it will be
		 * intercepted in mbm_erinfo_notify
		 */
		g_at_chat_send(nd->chat, "AT*ERINFO?", none_prefix,
				NULL, NULL, NULL);
		break;
	case OFONO_VENDOR_GOBI:
		/*
		 * Send *CNTI=0 to find out the current tech, it will be
		 * intercepted in gobi_cnti_notify
		 */
		g_at_chat_send(nd->chat, "AT*CNTI=0", none_prefix,
				NULL, NULL, NULL);
		break;
	case OFONO_VENDOR_NOVATEL:
		/*
		 * Send $CNTI=0 to find out the current tech, it will be
		 * intercepted in nw_cnti_notify
		 */
		g_at_chat_send(nd->chat, "AT$CNTI=0", none_prefix,
				NULL, NULL, NULL);
		break;
	case OFONO_VENDOR_OPTION_HSO:
		/*
		 * Send AT_OCTI?;_OUWCTI? to find out the current tech,
		 * option_tech_cb will call fire CREG? to do the rest.
		 */
		if (g_at_chat_send(nd->chat, "AT_OCTI?;_OUWCTI?",
					option_tech_prefix,
					option_tech_cb, cbd, NULL) == 0)
			nd->tech = -1;
		break;
	}

	if (g_at_chat_send(nd->chat, "AT+CREG?", creg_prefix,
				at_creg_cb, cbd, g_free) > 0)
		return;

	g_free(cbd);

	CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, data);
}
Пример #15
0
static void start_dial(gboolean ok, GAtResult *result, gpointer user_data)
{
	if (!ok) {
		g_print("Checking PIN status failed\n");
		exit(1);
	}

	g_at_chat_send(control, "AT+CREG=2", none_prefix, NULL, NULL, NULL);
	g_at_chat_send(control, "AT+CGREG=2", none_prefix, NULL, NULL, NULL);

	g_at_chat_send(control, "AT+COPS=0", none_prefix,
						register_cb, NULL, NULL);
}
Пример #16
0
Файл: ifx.c Проект: intgr/ofono
static void xgendata_query(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct ofono_modem *modem = user_data;
	struct ifx_data *data = ofono_modem_get_data(modem);
	GAtResultIter iter;
	const char *gendata;

	DBG("");

	if (!ok)
		goto error;

	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "+XGENDATA:"))
		goto error;

	if (!g_at_result_iter_next_string(&iter, &gendata))
		goto error;

	DBG("\n%s", gendata);

	/* switch to GSM character set instead of IRA */
	g_at_chat_send(data->dlcs[AUX_DLC], "AT+CSCS=\"GSM\"", none_prefix,
							NULL, NULL, NULL);

	/* disable UART for power saving */
	g_at_chat_send(data->dlcs[AUX_DLC], "AT+XPOW=0,0,0", none_prefix,
							NULL, NULL, NULL);

	data->have_sim = FALSE;

	/* notify that the modem is ready so that pre_sim gets called */
	ofono_modem_set_powered(modem, TRUE);

	g_at_chat_register(data->dlcs[AUX_DLC], "+XSIM:", xsim_notify,
						FALSE, modem, NULL);

	/* enable XSIM and XLOCK notifications */
	g_at_chat_send(data->dlcs[AUX_DLC], "AT+XSIMSTATE=1", none_prefix,
						NULL, NULL, NULL);

	g_at_chat_send(data->dlcs[AUX_DLC], "AT+XSIMSTATE?", xsimstate_prefix,
					xsimstate_query, modem, NULL);

	return;

error:
	shutdown_device(data);
	ofono_modem_set_powered(modem, FALSE);
}
Пример #17
0
static void creg_notify(GAtResult *result, gpointer user_data)
{
	struct ofono_netreg *netreg = user_data;
	int status, lac, ci, tech;
	struct netreg_data *nd = ofono_netreg_get_data(netreg);
	struct tech_query *tq;

	if (at_util_parse_reg_unsolicited(result, "+CREG:", &status,
				&lac, &ci, &tech, nd->vendor) == FALSE)
		return;

	if (status != 1 && status != 5)
		goto notify;

	tq = g_try_new0(struct tech_query, 1);
	if (tq == NULL)
		goto notify;

	tq->status = status;
	tq->lac = lac;
	tq->ci = ci;
	tq->netreg = netreg;

	switch (nd->vendor) {
	case OFONO_VENDOR_GOBI:
		if (g_at_chat_send(nd->chat, "AT*CNTI=0", none_prefix,
					cnti_query_tech_cb, tq, g_free) > 0)
			return;
		break;
	case OFONO_VENDOR_NOVATEL:
		if (g_at_chat_send(nd->chat, "AT$CNTI=0", none_prefix,
					cnti_query_tech_cb, tq, g_free) > 0)
			return;
		break;
	case OFONO_VENDOR_OPTION_HSO:
		if (g_at_chat_send(nd->chat, "AT_OCTI?;_OUWCTI?",
					option_tech_prefix,
					option_query_tech_cb, tq, g_free) > 0)
			return;
		break;
	}

	g_free(tq);

	if ((status == 1 || status == 5) && tech == -1)
		tech = nd->tech;

notify:
	ofono_netreg_status_notify(netreg, status, lac, ci, tech);
}
Пример #18
0
static void hfp16_card_connect(struct ofono_handsfree_card *card,
					ofono_handsfree_card_connect_cb_t cb,
					void *data)
{
	struct hfp *hfp = ofono_handsfree_card_get_data(card);
	struct hfp_slc_info *info = &hfp->info;

	if (info->hf_features & HFP_HF_FEATURE_CODEC_NEGOTIATION &&
			info->ag_features & HFP_AG_FEATURE_CODEC_NEGOTIATION) {
		struct cb_data *cbd = cb_data_new(cb, data);

		cbd->user = card;
		hfp->bcc_id = g_at_chat_send(info->chat, "AT+BCC",
						none_prefix, bcc_cb,
						cbd, g_free);
		return;
	}

	/*
	 * If any side (remote or local) doesn't support codec negotiation,
	 * fallback to direct SCO connection. Calling connect_sco()
	 * hands the connection responsibility to the core, so no need
	 * to call the callback
	 */
	ofono_handsfree_card_connect_sco(card);
}
Пример #19
0
static void bcs_notify(GAtResult *result, gpointer user_data)
{
	struct hfp *hfp = user_data;
	struct hfp_slc_info *info = &hfp->info;
	GAtResultIter iter;
	char str[32];
	int value;

	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "+BCS:"))
		return;

	if (!g_at_result_iter_next_number(&iter, &value))
		return;

	if (ofono_handsfree_card_set_codec(hfp->card, value) == FALSE) {
		/* Unsupported codec, re-send our codecs */
		if (ofono_handsfree_audio_has_wideband())
			sprintf(str, "AT+BAC=%d,%d", HFP_CODEC_CVSD,
							HFP_CODEC_MSBC);
		else
			sprintf(str, "AT+BAC=%d", HFP_CODEC_CVSD);

		goto done;
	}

	/* Confirm the codec */
	sprintf(str, "AT+BCS=%d", value);

done:
	g_at_chat_send(info->chat, str, none_prefix, NULL, NULL, NULL);
}
Пример #20
0
static void at_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct ofono_gprs_context *gc = user_data;
	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
	char buf[64];

	if (!ok) {
		struct ofono_error error;

		gcd->active_context = 0;
		gcd->state = STATE_IDLE;

		decode_at_error(&error, g_at_result_final_response(result));
		gcd->up_cb(&error, NULL, 0, NULL, NULL, NULL, NULL,
				gcd->cb_data);
		return;
	}

	sprintf(buf, "AT+CGDATA=\"PPP\",%u", gcd->active_context);
	if (g_at_chat_send(gcd->chat, buf, none_prefix,
				at_cgdata_cb, gc, NULL) > 0)
		return;

	gcd->active_context = 0;
	gcd->state = STATE_IDLE;

	CALLBACK_WITH_FAILURE(gcd->up_cb, NULL, 0, NULL, NULL, NULL, NULL,
				gcd->cb_data);
}
Пример #21
0
static void at_gprs_activate_primary(struct ofono_gprs_context *gc,
				const struct ofono_gprs_primary_context *ctx,
				ofono_gprs_context_up_cb_t cb, void *data)
{
	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
	char buf[OFONO_GPRS_MAX_APN_LENGTH + 128];
	int len;

	gcd->active_context = ctx->cid;
	gcd->up_cb = cb;
	gcd->cb_data = data;
	memcpy(gcd->username, ctx->username, sizeof(ctx->username));
	memcpy(gcd->password, ctx->password, sizeof(ctx->password));

	gcd->state = STATE_ENABLING;

	len = snprintf(buf, sizeof(buf), "AT+CGDCONT=%u,\"IP\"", ctx->cid);

	if (ctx->apn)
		snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
				ctx->apn);

	if (g_at_chat_send(gcd->chat, buf, none_prefix,
				at_cgdcont_cb, gc, NULL) > 0)
		return;

	CALLBACK_WITH_FAILURE(cb, NULL, 0, NULL, NULL, NULL, NULL, data);
}
Пример #22
0
static void mbm_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	ofono_gprs_context_up_cb_t cb = cbd->cb;
	struct ofono_gprs_context *gc = cbd->user;
	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
	struct cb_data *ncbd;
	char buf[64];

	if (!ok) {
		struct ofono_error error;

		gcd->active_context = 0;

		decode_at_error(&error, g_at_result_final_response(result));
		cb(&error, NULL, 0, NULL, NULL, NULL, NULL, cbd->data);
		return;
	}

	ncbd = g_memdup(cbd, sizeof(struct cb_data));

	snprintf(buf, sizeof(buf), "AT*ENAP=1,%u", gcd->active_context);

	if (g_at_chat_send(gcd->chat, buf, none_prefix,
				mbm_enap_up_cb, ncbd, g_free) > 0)
		return;

	if (ncbd)
		g_free(ncbd);

	gcd->active_context = 0;

	CALLBACK_WITH_FAILURE(cb, NULL, 0, NULL, NULL, NULL, NULL, cbd->data);
}
Пример #23
0
static void icera_set_rat_mode(struct ofono_radio_settings *rs,
				enum ofono_radio_access_mode mode,
				ofono_radio_settings_rat_mode_set_cb_t cb,
				void *data)
{
	struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
	struct cb_data *cbd = cb_data_new(cb, data);
	char buf[20];
	int value = 5;

	switch (mode) {
	case OFONO_RADIO_ACCESS_MODE_ANY:
		value = 5;
		break;
	case OFONO_RADIO_ACCESS_MODE_GSM:
		value = 0;
		break;
	case OFONO_RADIO_ACCESS_MODE_UMTS:
		value = 1;
		break;
	case OFONO_RADIO_ACCESS_MODE_LTE:
		goto error;
	}

	snprintf(buf, sizeof(buf), "AT%%IPSYS=%u,2", value);

	if (g_at_chat_send(rsd->chat, buf, none_prefix,
					ipsys_modify_cb, cbd, g_free) > 0)
		return;

error:
	CALLBACK_WITH_FAILURE(cb, data);
	g_free(cbd);
}
Пример #24
0
static void ublox_send_uauthreq(struct ofono_gprs_context *gc,
				const char *username, const char *password,
				enum ofono_gprs_auth_method auth_method)

{
	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
	char buf[UBLOX_MAX_USER_LEN + UBLOX_MAX_PASS_LEN + 32];
	unsigned auth;

	switch (auth_method) {
	case OFONO_GPRS_AUTH_METHOD_PAP:
		auth = 1;
		break;
	case OFONO_GPRS_AUTH_METHOD_CHAP:
		auth = 2;
		break;
	default:
		ofono_error("Unsupported auth type %u", auth_method);
		return;
	}

	snprintf(buf, sizeof(buf), "AT+UAUTHREQ=%u,%u,\"%s\",\"%s\"",
			gcd->active_context, auth, username, password);

	/* If this failed, we will see it during context activation. */
	g_at_chat_send(gcd->chat, buf, none_prefix, NULL, NULL, NULL);
}
Пример #25
0
static void mbm_enap_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
	struct cb_data *cbd = user_data;
	ofono_gprs_context_up_cb_t cb = cbd->cb;
	struct ofono_gprs_context *gc = cbd->user;
	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
	struct ofono_error error;

	if (ok) {
		gcd->mbm_state = MBM_ENABLING;
		gcd->up_cb = cb;
		gcd->cb_data = cbd->data;

		if (gcd->have_e2nap == FALSE)
			g_at_chat_send(gcd->chat, "AT*ENAP?", enap_prefix,
					mbm_enap_poll_cb, gc, NULL);

		return;
	}

	gcd->active_context = 0;

	decode_at_error(&error, g_at_result_final_response(result));
	cb(&error, NULL, FALSE, NULL, NULL, NULL, NULL, cbd->data);
}
Пример #26
0
static void at_cmgf_query_cb(gboolean ok, GAtResult *result,
				gpointer user_data)
{
	struct ofono_sms *sms = user_data;
	struct sms_data *data = ofono_sms_get_data(sms);
	gboolean supported = FALSE;

	if (ok) {
		GAtResultIter iter;
		int mode;

		g_at_result_iter_init(&iter, result);

		if (!g_at_result_iter_next(&iter, "+CMGF:"))
			goto out;

		if (!g_at_result_iter_open_list(&iter))
			goto out;

		/* Look for mode 0 (PDU mode) */
		while (g_at_result_iter_next_number(&iter, &mode))
			if (mode == 0)
				supported = TRUE;
	}

out:
	if (!supported)
		return at_sms_not_supported(sms);

	g_at_chat_send(data->chat, "AT+CPMS=?", cpms_prefix,
			at_cpms_query_cb, sms, NULL);
}
Пример #27
0
static void at_query_cnmi(struct ofono_sms *sms)
{
	struct sms_data *data = ofono_sms_get_data(sms);

	g_at_chat_send(data->chat, "AT+CNMI=?", cnmi_prefix,
			at_cnmi_query_cb, sms, NULL);
}
Пример #28
0
static void at_cmgl_set_cpms(struct ofono_sms *sms, int store)
{
	struct sms_data *data = ofono_sms_get_data(sms);

	if (store == data->store) {
		struct cpms_request req;

		req.sms = sms;
		req.store = store;

		at_cmgl_cpms_cb(TRUE, NULL, &req);
	} else {
		char buf[128];
		const char *readwrite = storages[store];
		const char *incoming = storages[data->incoming];
		struct cpms_request *req = g_new(struct cpms_request, 1);

		req->sms = sms;
		req->store = store;

		snprintf(buf, sizeof(buf), "AT+CPMS=\"%s\",\"%s\",\"%s\"",
				readwrite, readwrite, incoming);

		g_at_chat_send(data->chat, buf, cpms_prefix, at_cmgl_cpms_cb,
				req, g_free);
	}
}
Пример #29
0
static void at_send_cmgr_cpms(struct ofono_sms *sms, int store, int index,
				gboolean expect_sr)
{
	struct sms_data *data = ofono_sms_get_data(sms);

	if (store == data->store) {
		struct cpms_request req;

		req.sms = sms;
		req.store = store;
		req.index = index;
		req.expect_sr = expect_sr;

		at_cmgr_cpms_cb(TRUE, NULL, &req);
	} else {
		char buf[128];
		const char *incoming = storages[data->incoming];
		struct cpms_request *req = g_new(struct cpms_request, 1);

		req->sms = sms;
		req->store = store;
		req->index = index;
		req->expect_sr = expect_sr;

		snprintf(buf, sizeof(buf), "AT+CPMS=\"%s\",\"%s\",\"%s\"",
				storages[store], storages[store], incoming);

		g_at_chat_send(data->chat, buf, cpms_prefix, at_cmgr_cpms_cb,
				req, g_free);
	}
}
Пример #30
0
static void at_csms_query_cb(gboolean ok, GAtResult *result,
				gpointer user_data)
{
	struct ofono_sms *sms = user_data;
	struct sms_data *data = ofono_sms_get_data(sms);
	gboolean cnma_supported = FALSE;
	GAtResultIter iter;
	int status_min, status_max;
	char buf[128];

	if (!ok)
		return at_sms_not_supported(sms);

	g_at_result_iter_init(&iter, result);

	if (!g_at_result_iter_next(&iter, "+CSMS:"))
		goto out;

	if (!g_at_result_iter_open_list(&iter))
		goto out;

	while (g_at_result_iter_next_range(&iter, &status_min, &status_max))
		if (status_min <= 1 && 1 <= status_max)
			cnma_supported = TRUE;

	DBG("CSMS query parsed successfully");

out:
	snprintf(buf, sizeof(buf), "AT+CSMS=%d", cnma_supported ? 1 : 0);
	g_at_chat_send(data->chat, buf, csms_prefix,
			at_csms_set_cb, sms, NULL);
}