Lines Matching +full:connected +full:- +full:ground
4 * SPDX-License-Identifier: Apache-2.0
13 #include <zephyr/drivers/modem/simcom-sim7080.h>
14 #include "simcom-sim7080.h"
55 struct sim7080_data *data = dev->data; in modem_get_mac()
58 data->mac_addr[0] = 0x00; in modem_get_mac()
59 data->mac_addr[1] = 0x10; in modem_get_mac()
64 UNALIGNED_PUT(hash_value, (uint32_t *)(data->mac_addr + 2)); in modem_get_mac()
66 return data->mac_addr; in modem_get_mac()
75 struct sim7080_data *data = dev->data; in modem_net_iface_init()
77 net_if_set_link_addr(iface, modem_get_mac(dev), sizeof(data->mac_addr), NET_LINK_ETHERNET); in modem_net_iface_init()
79 data->netif = iface; in modem_net_iface_init()
144 return -EAGAIN; in offload_connect()
148 LOG_ERR("Invalid socket id %d from fd %d", sock->id, sock->sock_fd); in offload_connect()
150 return -1; in offload_connect()
153 if (sock->is_connected == true) { in offload_connect()
154 LOG_ERR("Socket is already connected! id: %d, fd: %d", sock->id, sock->sock_fd); in offload_connect()
156 return -1; in offload_connect()
160 if (addr->sa_family == AF_INET6) { in offload_connect()
161 dst_port = ntohs(net_sin6(addr)->sin6_port); in offload_connect()
162 } else if (addr->sa_family == AF_INET) { in offload_connect()
163 dst_port = ntohs(net_sin(addr)->sin_port); in offload_connect()
167 protocol = (sock->type == SOCK_STREAM) ? "TCP" : "UDP"; in offload_connect()
173 return -1; in offload_connect()
176 ret = snprintk(buf, sizeof(buf), "AT+CAOPEN=%d,%d,\"%s\",\"%s\",%d", 0, sock->id, in offload_connect()
179 LOG_ERR("Failed to build connect command. ID: %d, FD: %d", sock->id, sock->sock_fd); in offload_connect()
181 return -1; in offload_connect()
199 sock->is_connected = true; in offload_connect()
203 errno = -ret; in offload_connect()
204 return -1; in offload_connect()
228 return -EAGAIN; in offload_sendto()
234 return -1; in offload_sendto()
237 /* Socket has to be connected. */ in offload_sendto()
238 if (!sock->is_connected) { in offload_sendto()
240 return -1; in offload_sendto()
248 ret = snprintk(send_buf, sizeof(send_buf), "AT+CASEND=%d,%ld", sock->id, (long)len); in offload_sendto()
252 return -1; in offload_sendto()
291 errno = -ret; in offload_sendto()
292 return -1; in offload_sendto()
313 return -EAGAIN; in sockread_common()
316 if (!data->rx_buf) { in sockread_common()
318 return -EINVAL; in sockread_common()
323 return -EAGAIN; in sockread_common()
326 if (net_buf_frags_len(data->rx_buf) < socket_data_length) { in sockread_common()
327 LOG_DBG("Not enough data -- wait!"); in sockread_common()
328 return -EAGAIN; in sockread_common()
334 ret = -EINVAL; in sockread_common()
338 sock_data = (struct socket_read_data *)sock->data; in sockread_common()
341 ret = -EINVAL; in sockread_common()
345 ret = net_buf_linearize(sock_data->recv_buf, sock_data->recv_buf_len, data->rx_buf, 0, in sockread_common()
347 data->rx_buf = net_buf_skip(data->rx_buf, ret); in sockread_common()
348 sock_data->recv_read_len = ret; in sockread_common()
353 ret = -EINVAL; in sockread_common()
360 modem_socket_packet_size_update(&mdata.socket_config, sock, -packet_size); in sockread_common()
388 return -EAGAIN; in offload_recvfrom()
393 return -1; in offload_recvfrom()
398 return -1; in offload_recvfrom()
405 return -1; in offload_recvfrom()
413 snprintk(sendbuf, sizeof(sendbuf), "AT+CARECV=%d,%zd", sock->id, max_len); in offload_recvfrom()
419 sock->data = &sock_data; in offload_recvfrom()
420 mdata.current_sock_fd = sock->sock_fd; in offload_recvfrom()
425 errno = -ret; in offload_recvfrom()
426 ret = -1; in offload_recvfrom()
432 *addrlen = sizeof(sock->dst); in offload_recvfrom()
433 memcpy(src_addr, &sock->dst, *addrlen); in offload_recvfrom()
441 mdata.current_sock_fd = -1; in offload_recvfrom()
442 sock->data = NULL; in offload_recvfrom()
460 return -EAGAIN; in offload_sendmsg()
463 if (sock->type == SOCK_DGRAM) { in offload_sendmsg()
470 return -1; in offload_sendmsg()
474 for (int i = 0; i < msg->msg_iovlen; i++) { in offload_sendmsg()
475 buf = msg->msg_iov[i].iov_base; in offload_sendmsg()
476 len = msg->msg_iov[i].iov_len; in offload_sendmsg()
479 ret = offload_sendto(obj, buf, len, flags, msg->msg_name, msg->msg_namelen); in offload_sendmsg()
481 if (ret == -EAGAIN) { in offload_sendmsg()
489 len -= ret; in offload_sendmsg()
505 snprintk(buf, sizeof(buf), "AT+CACLOSE=%d", sock->id); in socket_close()
513 modem_socket_put(&mdata.socket_config, sock->sock_fd); in socket_close()
542 return -EAGAIN; in offload_close()
550 /* Close the socket only if it is connected. */ in offload_close()
551 if (sock->is_connected) { in offload_close()
569 return -EAGAIN; in offload_poll()
583 return -1; in offload_poll()
597 return -EXDEV; in offload_ioctl()
600 return -EOPNOTSUPP; in offload_ioctl()
616 return -1; in offload_ioctl()
652 int ret = -1; in MODEM_CMD_DEFINE()
661 out_len = net_buf_linearize(ips, sizeof(ips) - 1, data->rx_buf, 1, len); in MODEM_CMD_DEFINE()
674 &((struct sockaddr_in *)&dns_result_addr)->sin_addr); in MODEM_CMD_DEFINE()
720 net_sin(&dns_result_addr)->sin_port = htons(port); in offload_getaddrinfo()
726 &((struct sockaddr_in *)&dns_result_addr)->sin_addr) == 0) { in offload_getaddrinfo()
732 if (hints && hints->ai_flags & AI_NUMERICHOST) { in offload_getaddrinfo()
794 errno = -ret; in offload_socket()
795 return -1; in offload_socket()
828 modem_cmd_handler_set_error(data, -EIO); in MODEM_CMD_DEFINE()
835 modem_cmd_handler_set_error(data, -EIO); in MODEM_CMD_DEFINE()
895 * 0 - Closed by remote server or error
896 * 1 - Connected to remote server
897 * 2 - Listening
919 sock->is_connected = false; in MODEM_CMD_DEFINE()
936 * - 1 for data available/opened session.
937 * - 0 If transfer is finished.
938 * - >0 for some error.
966 mdata.mdm_manufacturer, sizeof(mdata.mdm_manufacturer) - 1, data->rx_buf, 0, len); in MODEM_CMD_DEFINE()
977 size_t out_len = net_buf_linearize(mdata.mdm_model, sizeof(mdata.mdm_model) - 1, in MODEM_CMD_DEFINE()
978 data->rx_buf, 0, len); in MODEM_CMD_DEFINE()
994 out_len = net_buf_linearize(mdata.mdm_revision, sizeof(mdata.mdm_revision) - 1, in MODEM_CMD_DEFINE()
995 data->rx_buf, 0, len); in MODEM_CMD_DEFINE()
1015 net_buf_linearize(mdata.mdm_imei, sizeof(mdata.mdm_imei) - 1, data->rx_buf, 0, len); in MODEM_CMD_DEFINE()
1028 net_buf_linearize(mdata.mdm_imsi, sizeof(mdata.mdm_imsi) - 1, data->rx_buf, 0, len); in MODEM_CMD_DEFINE()
1041 size_t out_len = net_buf_linearize(mdata.mdm_iccid, sizeof(mdata.mdm_iccid) - 1, in MODEM_CMD_DEFINE()
1042 data->rx_buf, 0, len); in MODEM_CMD_DEFINE()
1079 * rssi: 0,-115dBm; 1,-111dBm; 2...30,-110...-54dBm; 31,-52dBm or greater.
1088 mdata.mdm_rssi = -115; in MODEM_CMD_DEFINE()
1090 mdata.mdm_rssi = -111; in MODEM_CMD_DEFINE()
1092 mdata.mdm_rssi = -114 + 2 * rssi; in MODEM_CMD_DEFINE()
1094 mdata.mdm_rssi = -52; in MODEM_CMD_DEFINE()
1096 mdata.mdm_rssi = -1000; in MODEM_CMD_DEFINE()
1172 return -1; in modem_pdp_activate()
1180 return -1; in modem_pdp_activate()
1185 return -1; in modem_pdp_activate()
1200 return -1; in modem_pdp_activate()
1208 ret = -1; in modem_pdp_activate()
1233 ret = -1; in modem_pdp_activate()
1271 SETUP_CMD_NOHANDLE("AT+CBANDCFG=\"NB-IOT\"," MDM_LTE_BANDS),
1276 SETUP_CMD_NOHANDLE("AT+CBANDCFG=\"CAT-M\"," MDM_LTE_BANDS),
1319 return -1; in modem_autobaud()
1391 return -1; in gnss_split_on_dot()
1400 *f2 = -*f2; in gnss_split_on_dot()
1469 strncpy(gnss_data.utc, utc, sizeof(gnss_data.utc) - 1); in parse_cgnsinf()
1522 return -1; in parse_cgnsinf()
1532 * <Latitude>,<Longitude>,<MSL Altitude>,<Speed Over Ground>,
1533 * <Course Over Ground>,<Fix Mode>,<Reserved1>,<HDOP>,<PDOP>,
1541 size_t out_len = net_buf_linearize(gps_buf, sizeof(gps_buf) - 1, data->rx_buf, 0, len); in MODEM_CMD_DEFINE()
1554 return -1; in mdm_sim7080_query_gnss()
1564 return -EAGAIN; in mdm_sim7080_query_gnss()
1586 return -1; in mdm_sim7080_start_gnss()
1592 return -1; in mdm_sim7080_start_gnss()
1625 if (net_buf_frags_len(data->rx_buf) <= nbytes + bytes_to_skip) { in MODEM_CMD_DEFINE()
1626 return -EAGAIN; in MODEM_CMD_DEFINE()
1629 out_len = net_buf_linearize(mdata.ftp.read_buffer, mdata.ftp.nread, data->rx_buf, in MODEM_CMD_DEFINE()
1634 data->rx_buf = net_buf_skip(data->rx_buf, nbytes + bytes_to_skip); in MODEM_CMD_DEFINE()
1698 return -1; in mdm_sim7080_ftp_get_start()
1706 return -1; in mdm_sim7080_ftp_get_start()
1713 return -1; in mdm_sim7080_ftp_get_start()
1720 return -1; in mdm_sim7080_ftp_get_start()
1727 return -1; in mdm_sim7080_ftp_get_start()
1734 return -1; in mdm_sim7080_ftp_get_start()
1741 return -1; in mdm_sim7080_ftp_get_start()
1748 return -1; in mdm_sim7080_ftp_get_start()
1755 return -1; in mdm_sim7080_ftp_get_start()
1762 return -1; in mdm_sim7080_ftp_get_start()
1769 return -1; in mdm_sim7080_ftp_get_start()
1776 return -1; in mdm_sim7080_ftp_get_start()
1783 return -1; in mdm_sim7080_ftp_get_start()
1790 return -1; in mdm_sim7080_ftp_get_start()
1803 return -1; in mdm_sim7080_ftp_get_start()
1807 LOG_WRN("Session state is not connected!"); in mdm_sim7080_ftp_get_start()
1808 return -1; in mdm_sim7080_ftp_get_start()
1820 return byte - '0'; in mdm_pdu_decode_ascii()
1822 return byte - 'A' + 10; in mdm_pdu_decode_ascii()
1824 return byte - 'a' + 10; in mdm_pdu_decode_ascii()
1872 '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', in mdm_decode_pdu()
1892 return -1; in mdm_decode_pdu()
1896 target_buf->first_octet = mdm_pdu_read_byte(pdu, index++); in mdm_decode_pdu()
1899 return -1; in mdm_decode_pdu()
1903 * first byte of addr field is the addr length -> skip it. in mdm_decode_pdu()
1904 * address type is not included in addr len -> add +1. in mdm_decode_pdu()
1914 return -1; in mdm_decode_pdu()
1918 target_buf->tp_pid = mdm_pdu_read_byte(pdu, index++); in mdm_decode_pdu()
1921 return -1; in mdm_decode_pdu()
1929 return -1; in mdm_decode_pdu()
1932 target_buf->time.year = mdm_pdu_read_time(pdu, index++); in mdm_decode_pdu()
1933 target_buf->time.month = mdm_pdu_read_time(pdu, index++); in mdm_decode_pdu()
1934 target_buf->time.day = mdm_pdu_read_time(pdu, index++); in mdm_decode_pdu()
1935 target_buf->time.hour = mdm_pdu_read_time(pdu, index++); in mdm_decode_pdu()
1936 target_buf->time.minute = mdm_pdu_read_time(pdu, index++); in mdm_decode_pdu()
1937 target_buf->time.second = mdm_pdu_read_time(pdu, index++); in mdm_decode_pdu()
1938 target_buf->time.timezone = mdm_pdu_read_time(pdu, index++); in mdm_decode_pdu()
1946 if (target_buf->first_octet & SMS_TP_UDHI_HEADER) { in mdm_decode_pdu()
1953 return -1; in mdm_decode_pdu()
1957 /* Read data according to type set in TP-DCS */ in mdm_decode_pdu()
1963 if (target_buf->first_octet & SMS_TP_UDHI_HEADER) { in mdm_decode_pdu()
1967 uint8_t fill_bits = 7 - ((header_skip * 8) % 7); in mdm_decode_pdu()
1975 fill_level = 8 - fill_bits; in mdm_decode_pdu()
1984 buf &= ((1 << fill_level) - 1); in mdm_decode_pdu()
1990 * Convert 7-bit encoded data to Unicode and in mdm_decode_pdu()
1991 * then to UTF-8 in mdm_decode_pdu()
1996 target_buf->data[data_index++] = letter & 0x007f; in mdm_decode_pdu()
1998 target_buf->data[data_index++] = 0xc0 | ((letter & 0x07c0) >> 6); in mdm_decode_pdu()
1999 target_buf->data[data_index++] = 0x80 | ((letter & 0x003f) >> 0); in mdm_decode_pdu()
2002 fill_level -= 7; in mdm_decode_pdu()
2004 target_buf->data_len = data_index; in mdm_decode_pdu()
2007 for (int idx = 0; idx < tp_udl - header_skip; idx++) { in mdm_decode_pdu()
2008 target_buf->data[idx] = mdm_pdu_read_byte(pdu, index++); in mdm_decode_pdu()
2010 target_buf->data_len = tp_udl; in mdm_decode_pdu()
2013 for (int idx = 0; idx < tp_udl - header_skip; idx++) { in mdm_decode_pdu()
2014 target_buf->data[idx] = mdm_pdu_read_byte(pdu, index++); in mdm_decode_pdu()
2016 target_buf->data_len = tp_udl; in mdm_decode_pdu()
2018 return -1; in mdm_decode_pdu()
2055 while (frag && skip >= frag->len) { in net_buf_find_crlf()
2056 skip -= frag->len; in net_buf_find_crlf()
2057 frag = frag->frags; in net_buf_find_crlf()
2067 while (frag && !is_crlf(frag->data + pos, frag->len - pos)) { in net_buf_find_crlf()
2068 if (pos + 1 >= frag->len) { in net_buf_find_crlf()
2069 len += frag->len; in net_buf_find_crlf()
2070 frag = frag->frags; in net_buf_find_crlf()
2077 if (frag && is_crlf(frag->data + pos, frag->len - pos)) { in net_buf_find_crlf()
2079 return len - skip; in net_buf_find_crlf()
2109 param_len = net_buf_find_crlf(data->rx_buf, 0); in MODEM_CMD_DEFINE()
2112 return -EAGAIN; in MODEM_CMD_DEFINE()
2116 sms_len = net_buf_find_crlf(data->rx_buf, param_len + 2); in MODEM_CMD_DEFINE()
2118 return -EAGAIN; in MODEM_CMD_DEFINE()
2122 data->rx_buf = net_buf_skip(data->rx_buf, param_len + 2); in MODEM_CMD_DEFINE()
2124 out_len = net_buf_linearize(pdu_buffer, sizeof(pdu_buffer) - 1, data->rx_buf, 0, sms_len); in MODEM_CMD_DEFINE()
2127 data->rx_buf = net_buf_skip(data->rx_buf, sms_len); in MODEM_CMD_DEFINE()
2135 if (mdata.sms_buffer_pos >= mdata.sms_buffer->nsms) { in MODEM_CMD_DEFINE()
2139 sms = &mdata.sms_buffer->sms[mdata.sms_buffer_pos]; in MODEM_CMD_DEFINE()
2146 sms->stat = sms_stat; in MODEM_CMD_DEFINE()
2147 sms->index = sms_index; in MODEM_CMD_DEFINE()
2148 sms->data[sms->data_len] = '\0'; in MODEM_CMD_DEFINE()
2166 return -1; in mdm_sim7080_read_sms()
2179 return -1; in mdm_sim7080_delete_sms()
2185 return -1; in mdm_sim7080_delete_sms()
2224 (mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000)) { in modem_setup()
2229 if (mdata.mdm_rssi >= 0 || mdata.mdm_rssi <= -1000) { in modem_setup()
2231 ret = -ENETUNREACH; in modem_setup()
2276 while (tries--) { in mdm_sim7080_power_off()
2281 while (autobaud_tries--) { in mdm_sim7080_power_off()
2295 return -1; in mdm_sim7080_power_off()
2386 mdata.current_sock_fd = -1; in modem_init()