*****************************************************************************/
#define INSTANCE_NAME_LEN 63
-#define SERVICE_TYPE_LEN 15
+#define MAX_SERVICE_NAME_LEN 15
+#define MAX_SERVICE_TYPE_LEN 255
#define PROTO_LEN 4
#define KEY_LEN 9 /* http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt */
#define KEY_MIN 0x20 /* RFC 20 */
return ASP_ERROR_NONE;
}
-static bool __is_valid_service_name(char *service_name)
+static bool __is_valid_service_type_for_wfds(char *service_type)
{
int pos = 0;
- while(service_name[pos] != 0) {
- if (!g_ascii_isalpha(service_name[pos]) &&
- !g_ascii_isdigit(service_name[pos]) &&
- service_name[pos] != '.' &&
- service_name[pos] != '-')
+
+ /* Wi-Fi Peer-to-Peer Services Technical Specification v1.1
+ * The UTF-8 encoded service name (and therefore the contents
+ * of each service_name parameter) shall be 255 bytes or less
+ */
+ if (strlen(service_type) > MAX_SERVICE_TYPE_LEN)
+ return false;
+
+ while(service_type[pos] != 0) {
+ if (!g_ascii_isalpha(service_type[pos]) &&
+ !g_ascii_isdigit(service_type[pos]) &&
+ service_type[pos] != '.' &&
+ service_type[pos] != '-')
return false;
pos++;
}
static bool __is_valid_service_type(char *service_type)
{
- int type_len = strlen(service_type) - PROTO_LEN - 1;
- char *proto = &(service_type[type_len + 1]);
- int pos = 1;
+ int srv_name_len = strlen(service_type) - PROTO_LEN - 1;
+ char *proto;
+ int pos;
+
+ if(srv_name_len < 2)
+ return __is_valid_service_type_for_wfds(service_type);
+ proto = &(service_type[srv_name_len + 1]);
if (strncmp(proto, "_udp", PROTO_LEN) != 0 && strncmp(proto, "_tcp", PROTO_LEN) != 0)
- return __is_valid_service_name(service_type);
+ return __is_valid_service_type_for_wfds(service_type);
+
+ /* Service Type = <_>service_name.<_><Transport protocol>
+ * Service Name description:
+ * Shall be at least 1 character and no more than 15 characters long
+ * Shall contain only US-ASCII [ANSI.X3.4-1986] letters 'A' - 'Z' and
+ * 'a' - 'z', digits '0' - '9', and hyphens ('-', ASCII 0x2D or decimal 45)
+ * Shall contain at least one letter ('A' - 'Z' or 'a' - ‘z')
+ * Shall NOT begin or end with a hyphen
+ */
+
+ if (srv_name_len > MAX_SERVICE_NAME_LEN + 1)
+ return false;
- if (type_len > SERVICE_TYPE_LEN + 1)
+ if (service_type[0] != '_' || service_type[1] == '-' ||
+ service_type[srv_name_len] != '.')
return false;
- while (pos < type_len) {
+ pos = 1;
+ while (pos < srv_name_len) {
if (!g_ascii_isalpha(service_type[pos]) &&
!g_ascii_isdigit(service_type[pos]) &&
service_type[pos] != '-')
return false;
pos++;
}
+
return true;
}
__ASP_LOG_FUNC_END__;
return ASP_ERROR_INVALID_PARAMETER;
}
+
+ if (strlen(service_type) == 0) {
+ ASP_LOGE("Zero length value");
+ __ASP_LOG_FUNC_END__;
+ return ASP_ERROR_INVALID_PARAMETER;
+ }
+
ASP_LOGD("service [%p]", adv_service);
if (!__is_valid_service_type(service_type)) {