コード例 #1
0
ファイル: gprs-context.c プロジェクト: Herrie82/ofono-fix2
static int at_gprs_context_probe(struct ofono_gprs_context *gc,
					unsigned int vendor, void *data)
{
	GAtChat *chat = data;
	struct gprs_context_data *gcd;
	struct stat st;

	DBG("");

	if (stat(TUN_SYSFS_DIR, &st) < 0) {
		ofono_error("Missing support for TUN/TAP devices");
		return -ENODEV;
	}

	gcd = g_try_new0(struct gprs_context_data, 1);
	if (gcd == NULL)
		return -ENOMEM;

	gcd->chat = g_at_chat_clone(chat);
	gcd->vendor = vendor;

	ofono_gprs_context_set_data(gc, gcd);

	chat = g_at_chat_get_slave(gcd->chat);
	if (chat == NULL)
		return 0;

	g_at_chat_register(chat, "+CGEV:", cgev_notify, FALSE, gc, NULL);

	return 0;
}
コード例 #2
0
ファイル: gprs-context.c プロジェクト: Thread974/ofono
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);
}
コード例 #3
0
ファイル: gprs-context.c プロジェクト: Herrie82/ofono-fix2
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));

	/* We only support CHAP and PAP */
	switch (ctx->auth_method) {
	case OFONO_GPRS_AUTH_METHOD_CHAP:
		gcd->auth_method = G_AT_PPP_AUTH_METHOD_CHAP;
		break;
	case OFONO_GPRS_AUTH_METHOD_PAP:
		gcd->auth_method = G_AT_PPP_AUTH_METHOD_PAP;
		break;
	default:
		goto error;
	}

	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) {
		switch (gcd->vendor) {
		case OFONO_VENDOR_UBLOX:
			/*
			 * U-blox modems require a magic prefix to the APN to
			 * specify the authentication method to use in the
			 * network.  See UBX-13002752 - R21.
			 *
			 * As the response of the read command omits this magic
			 * prefix, this is the least invasive place to set it.
			 */
			switch (ctx->auth_method) {
			case OFONO_GPRS_AUTH_METHOD_CHAP:
				snprintf(buf + len, sizeof(buf) - len - 3,
						",\"CHAP:%s\"", ctx->apn);
				break;
			case OFONO_GPRS_AUTH_METHOD_PAP:
				snprintf(buf + len, sizeof(buf) - len - 3,
						",\"PAP:%s\"", ctx->apn);
				break;
			}
			break;
		default:
			snprintf(buf + len, sizeof(buf) - len - 3, ",\"%s\"",
					ctx->apn);
			break;
		}
	}

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

error:
	CALLBACK_WITH_FAILURE(cb, data);
}