示例#1
0
static int set_powered(DBusConnection *conn, struct manager *mgr, gboolean powered)
{
	const char *status;

	if (powered)
	{
		g_debug("Powering modem up ...");

		mgr->state = INITIALIZING;

		notify_status_changed(conn, mgr->state);

		if (ipc_client_bootstrap_modem(mgr->client) < 0 ||
			ipc_client_power_on(mgr->client) < 0) {
			g_error("Can't bootstrap and power on the modem");
			mgr->state = OFFLINE;
		}
		else {
			/* now start up the RFS client */
			if (rfs_manager_start(mgr->rfs) < 0) {
				g_error("Can't start RFS manager. Shutting down ...");
				ipc_client_power_off(mgr->client);
				mgr->state = OFFLINE;
			}
			else {
				notify_powered_changed(conn, powered);
				mgr->powered = powered;
				mgr->state = ONLINE;
				g_debug("Everything fine, modem is ready now.");
			}
		}
	}
	else {
		g_debug("Stopping RFS manager ...");
		rfs_manager_stop(mgr->rfs);

		g_debug("Powering modem down ...");
		ipc_client_power_off(mgr->client);

		mgr->powered = powered;
		notify_powered_changed(conn, powered);

		mgr->state = OFFLINE;
	}

	g_debug("Changed manager power state to %s", powered ? "online" : "offline");

	notify_status_changed(conn, mgr->state);

	return 0;
}
示例#2
0
int ipc_fmt_destroy(struct ril_client *client)
{
	struct ipc_client *ipc_client;

	int rc;

	if (client == NULL || client->data == NULL) {
		RIL_LOGE("Client was already destroyed");
		return 0;
	}

	ipc_client = (struct ipc_client *) client->data;

	RIL_LOGD("Destroying ipc fmt client");

	if (ipc_client != NULL) {
		ipc_client_power_off(ipc_client);
		ipc_client_close(ipc_client);
		ipc_client_data_destroy(ipc_client);
		ipc_client_destroy(ipc_client);
	}

	client->data = NULL;

	return 0;
}
示例#3
0
int aries_modem_bootstrap(struct ipc_client *client)
{
    int s3c2410_serial3_fd = -1;
    int onedram_fd = -1;

    /* Control variables. */
    int rc = 0;

    /* Boot variables */
    uint8_t *radio_img_p = NULL;
    uint32_t onedram_data = 0;
    uint8_t bootcore_version = 0;
    uint8_t info_size = 0;
    uint8_t crc_byte = 0;
    int block_size = 0;

    /* s3c2410 serial setup variables. */
    struct termios termios;
    int serial;

    /* fds maniplation variables */
    struct timeval timeout;
    fd_set fds;

    /* nv_data variables */
    void *nv_data_p;
    void *onedram_p;

    /* General purpose variables. */
    uint8_t data;
    uint16_t data_16;
    uint8_t *data_p;
    int i;

    ipc_client_log(client, "aries_ipc_bootstrap: enter");

    /* Read the radio.img image. */
    ipc_client_log(client, "aries_ipc_bootstrap: reading radio image");
    radio_img_p = ipc_client_mtd_read(client, "/dev/block/bml12", RADIO_IMG_READ_SIZE, RADIO_IMG_READ_SIZE);
    ipc_client_log(client, "aries_ipc_bootstrap: radio image read");

    ipc_client_log(client, "aries_ipc_bootstrap: open onedram");
    onedram_fd=open("/dev/onedram", O_RDWR);
    if(onedram_fd < 0)
        goto error;

    /* Reset the modem before init to send the first part of modem.img. */
    ipc_client_log(client, "aries_ipc_bootstrap: turning %s iface down", PHONET_IFACE);
    rc = phonet_iface_ifdown();
    if(rc < 0)
        goto error;

    ipc_client_power_off(client);
    ipc_client_log(client, "aries_ipc_bootstrap: sent PHONE \"off\" command");
    usleep(1000);

    ipc_client_power_on(client);
    ipc_client_log(client, "aries_ipc_bootstrap: sent PHONE \"on\" command");
    usleep(200000);

    ipc_client_log(client, "aries_ipc_bootstrap: open s3c2410_serial3");
    s3c2410_serial3_fd=open("/dev/s3c2410_serial3", O_RDWR);
    if(s3c2410_serial3_fd < 0)
        goto error;

    /* Setup the s3c2410 serial. */
    ipc_client_log(client, "aries_ipc_bootstrap: setup s3c2410_serial3");
    tcgetattr(s3c2410_serial3_fd, &termios);

    cfmakeraw(&termios);
    cfsetispeed(&termios, B115200);
    cfsetospeed(&termios, B115200);

    tcsetattr(s3c2410_serial3_fd, TCSANOW, &termios);

    /* Send 'AT' in ASCII. */
    ipc_client_log(client, "aries_ipc_bootstrap: sending AT in ASCII");
    for(i=0 ; i < 20 ; i++)
    {
        rc = write(s3c2410_serial3_fd, "AT", 2);
        usleep(50000);
    }
    ipc_client_log(client, "aries_ipc_bootstrap: sending AT in ASCII done");

    usleep(50000); //FIXME

    /* Write the first part of modem.img. */
    FD_ZERO(&fds);
    FD_SET(s3c2410_serial3_fd, &fds);

    timeout.tv_sec=5;
    timeout.tv_usec=0;

    if(select(FD_SETSIZE, &fds, NULL, NULL, &timeout) == 0)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
        goto error;
    }

    /* Get and check bootcore version. */
    read(s3c2410_serial3_fd, &bootcore_version, sizeof(bootcore_version));
    ipc_client_log(client, "aries_ipc_bootstrap: got bootcore version: 0x%x", bootcore_version);

    if(bootcore_version != BOOTCORE_VERSION)
        goto error;

    timeout.tv_sec=5;
    timeout.tv_usec=0;

    if(select(FD_SETSIZE, &fds, NULL, NULL, &timeout) == 0)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
        goto error;
    }

    /* Get info_size. */
    read(s3c2410_serial3_fd, &info_size, sizeof(info_size));
    ipc_client_log(client, "aries_ipc_bootstrap: got info_size: 0x%x", info_size);

    timeout.tv_sec=5;
    timeout.tv_usec=0;

    if(select(FD_SETSIZE, NULL, &fds, NULL, &timeout) == 0)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
        goto error;
    }

    /* Send PSI magic. */
    data=PSI_MAGIC;
    write(s3c2410_serial3_fd, &data, sizeof(data));
    ipc_client_log(client, "aries_ipc_bootstrap: sent PSI_MAGIC (0x%x)", PSI_MAGIC);

    /* Send PSI data len. */
    data_16=PSI_DATA_LEN;
    data_p=(uint8_t *)&data_16;

    for(i=0 ; i < 2 ; i++)
    {
        write(s3c2410_serial3_fd, data_p, 1);
        data_p++;
    }
    ipc_client_log(client, "aries_ipc_bootstrap: sent PSI_DATA_LEN (0x%x)", PSI_DATA_LEN);

    timeout.tv_sec=5;
    timeout.tv_usec=0;

    data_p=radio_img_p;

    ipc_client_log(client, "aries_ipc_bootstrap: sending the first part of radio.img");

    for(i=0 ; i < PSI_DATA_LEN ; i++)
    {
        if(select(FD_SETSIZE, NULL, &fds, NULL, &timeout) == 0)
        {
            ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
            goto error;
        }

        write(s3c2410_serial3_fd, data_p, 1);
        crc_byte=crc_byte ^ *data_p;

        data_p++;
    }

    ipc_client_log(client, "aries_ipc_bootstrap: first part of radio.img sent; crc_byte is 0x%x", crc_byte);

    timeout.tv_sec=5;
    timeout.tv_usec=0;

    if(select(FD_SETSIZE, NULL, &fds, NULL, &timeout) == 0)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
        goto error;
    }

    write(s3c2410_serial3_fd, &crc_byte, sizeof(crc_byte));

    ipc_client_log(client, "aries_ipc_bootstrap: crc_byte sent");

    data = 0;
    for(i = 0 ; data != 0x01 ; i++)
    {
        timeout.tv_sec=5;
        timeout.tv_usec=0;

        if(select(FD_SETSIZE, &fds, NULL, NULL, &timeout) == 0)
        {
            ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
            goto error;
        }

        read(s3c2410_serial3_fd, &data, sizeof(data));

        if(i > 50)
        {
            ipc_client_log(client, "aries_ipc_bootstrap: fairly too much attempts to get ACK");
            goto error;
        }
    }

    ipc_client_log(client, "aries_ipc_bootstrap: close s3c2410_serial3");
    close(s3c2410_serial3_fd);

    FD_ZERO(&fds);
    FD_SET(onedram_fd, &fds);

    timeout.tv_sec=5;
    timeout.tv_usec=0;

    ipc_client_log(client, "aries_ipc_bootstrap: wait for 0x12341234 from onedram");
    if(select(FD_SETSIZE, &fds, NULL, NULL, &timeout) == 0)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
        goto error;
    }

    read(onedram_fd, &onedram_data, sizeof(onedram_data));

    if(onedram_data != ONEDRAM_INIT_READ)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: wrong onedram init magic (got 0x%04x)", onedram_data);
        goto error;
    }

    ipc_client_log(client, "aries_ipc_bootstrap: got 0x%04x", onedram_data);

    ipc_client_log(client, "aries_ipc_bootstrap: writing the rest of modem.img to onedram.");

    /* Pointer to the remaining part of radio.img. */
    data_p=radio_img_p + PSI_DATA_LEN;

    onedram_p = mmap(NULL, ONENAND_MAP_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, onedram_fd, 0);

    if(onedram_p == NULL || onedram_p < 0 || onedram_p == 0xffffffff)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: could not map onedram to memory");
        goto error;
    }
 
    // it sometimes hangs here

    memcpy(onedram_p, data_p, RADIO_IMG_READ_SIZE - PSI_DATA_LEN);

    free(radio_img_p);

    /* nv_data part. */

    /* Check if all the nv_data files are ok. */
    if (nv_data_check(client) < 0)
        goto error;

    /* Check if the MD5 is ok. */
    if (nv_data_md5_check(client) < 0)
        goto error;

    /* Write nv_data.bin to modem_ctl. */
    ipc_client_log(client, "aries_ipc_bootstrap: write nv_data to onedram");

    nv_data_p = ipc_client_file_read(client, nv_data_path(client), nv_data_size(client), nv_data_chunk_size(client));
    if (nv_data_p == NULL)
        goto error;
    data_p = nv_data_p;

    memcpy(onedram_p + RADIO_IMG_MAX_SIZE, data_p, nv_data_size(client));

    free(nv_data_p);

    munmap(onedram_p, ONENAND_MAP_SIZE);

    if(ioctl(onedram_fd, ONEDRAM_REL_SEM) < 0)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: ONEDRAM_REL_SEM ioctl on onedram failed");
        goto error;
    }

    onedram_data = ONEDRAM_DEINIT_CMD;

    timeout.tv_sec=5;
    timeout.tv_usec=0;

    ipc_client_log(client, "aries_ipc_bootstrap: send 0x%04x", onedram_data);
    write(onedram_fd, &onedram_data, sizeof(onedram_data));

    if(select(FD_SETSIZE, &fds, NULL, NULL, &timeout) == 0)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: select timeout passed");
        goto error;
    }

    read(onedram_fd, &onedram_data, sizeof(onedram_data));

    if(onedram_data != ONEDRAM_DEINIT_READ)
    {
        ipc_client_log(client, "aries_ipc_bootstrap: wrong onedram deinit magic (got 0x%04x)", onedram_data);
        goto error;
    }

    ipc_client_log(client, "aries_ipc_bootstrap: got 0x%04x", onedram_data);

    close(onedram_fd);

    rc = 0;
    goto exit;

error:
    ipc_client_log(client, "aries_ipc_bootstrap: something went wrong");
    rc = -1;

exit:
    ipc_client_log(client, "aries_ipc_bootstrap: exit");
    return rc;
}
示例#4
0
int ipc_fmt_create(struct ril_client *client)
{
	struct ipc_client *ipc_client;

	int rc;

	if (client == NULL)
		return -EINVAL;

	RIL_LOGD("Creating new FMT client");

	ipc_client = ipc_client_create(IPC_CLIENT_TYPE_FMT);
	if (ipc_client == NULL) {
		RIL_LOGE("FMT client creation failed");
		goto error_client_create;
	}

	client->data = (void *) ipc_client;

	RIL_LOGD("Setting log handler");

	rc = ipc_client_set_log_callback(ipc_client, ipc_log_handler, NULL);
	if (rc < 0) {
		RIL_LOGE("Setting log handler failed");
		goto error_log_callback;
	}

	RIL_LOGD("Creating data");

	rc = ipc_client_data_create(ipc_client);
	if (rc < 0) {
		RIL_LOGE("Creating data failed");
		goto error_data_create;
	}

	RIL_LOGD("Starting bootstrap");

	rc = ipc_client_bootstrap(ipc_client);
	if (rc < 0) {
		RIL_LOGE("Modem bootstrap failed");
		goto error_bootstrap;
	}

	RIL_LOGD("Client power on...");

	rc = ipc_client_power_on(ipc_client);
	if (rc < 0) {
		RIL_LOGE("%s: failed to power on ipc client", __func__);
		goto error_power_on;
	}

	RIL_LOGD("Client open...");

	rc = ipc_client_open(ipc_client);
	if (rc < 0) {
		RIL_LOGE("%s: failed to open ipc client", __func__);
		goto error_open;
	}

	RIL_LOGD("IPC FMT client done");

	return 0;

error:
	ipc_client_power_off(ipc_client);

error_power_on:
error_get_fd:
	ipc_client_close(ipc_client);

error_open:
error_bootstrap:
	ipc_client_data_destroy(ipc_client);

error_data_create:
error_log_callback:
	ipc_client_destroy(ipc_client);

error_client_create:
	client->data = NULL;

	return -1;
}