This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

w_lte_lc_init_and_connect() infinite loop

This function has a potential infinite while loop.  Is there a mechanism to poll the socket outside of this function?

static int w_lte_lc_init_and_connect(struct device *unused)
{
	int err;
	int at_socket_fd;

	u8_t buffer[LC_MAX_READ_LENGTH];

	at_socket_fd = socket(AF_LTE, 0, NPROTO_AT);
	if (at_socket_fd == -1) {
		return -EFAULT;
	}

#if defined(CONFIG_LTE_EDRX_REQ)
	/* Request configured eDRX settings to save power */
	err = at_cmd(at_socket_fd, edrx_req, AT_CMD_SIZE(edrx_req));
	if (err) {
		close(at_socket_fd);
		return err;
	}
#endif
	err = at_cmd(at_socket_fd, subscribe, AT_CMD_SIZE(subscribe));
	if (err) {
		close(at_socket_fd);
		return err;
	}

#if defined(CONFIG_LTE_LOCK_BANDS)
	/* Set LTE band lock (volatile setting).
	 * Has to be done every time before activating the modem.
	 */
	err = at_cmd(at_socket_fd, lock_bands, AT_CMD_SIZE(lock_bands));
	if (err) {
		close(at_socket_fd);
		return err;
	}
#endif
#if defined(CONFIG_LTE_LEGACY_PCO_MODE)
	err = at_cmd(at_socket_fd, legacy_pco, AT_CMD_SIZE(legacy_pco));
	if (err) {
		close(at_socket_fd);
		return err;
	}
	LOG_INF("Using legacy LTE PCO mode...");
#endif
#if defined(CONFIG_LTE_PDP_CMD)
	err = at_cmd(at_socket_fd, cgdcont, AT_CMD_SIZE(cgdcont));
	if (err) {
		close(at_socket_fd);
		return err;
	}
	LOG_INF("PDP Context: %s", cgdcont);
#endif
	err = at_cmd(at_socket_fd, network_mode, AT_CMD_SIZE(network_mode));
	if (err) {
		close(at_socket_fd);
		return err;
	}
	err = at_cmd(at_socket_fd, normal, AT_CMD_SIZE(normal));
	if (err) {
		close(at_socket_fd);
		return err;
	}

	while (true) {
		int bytes;

		bytes = recv(at_socket_fd, buffer, LC_MAX_READ_LENGTH, 0);
		if (bytes) {
			LOG_DBG("recv: %s", buffer);
			if (!memcmp(status1, buffer, AT_CMD_SIZE(status1)) ||
			    !memcmp(status2, buffer, AT_CMD_SIZE(status2)) ||
			    !memcmp(status3, buffer, AT_CMD_SIZE(status3)) ||
			    !memcmp(status4, buffer, AT_CMD_SIZE(status4))) {
				break;
			}
		}
	}

	close(at_socket_fd);
	return 0;
}

Related