Ejemplo n.º 1
0
static void reply_known_capabilities(List *caps, List *req, WSPMachine *m) {
	unsigned long ui;
	Capability *cap;
	Octstr *data;

	if (wsp_cap_count(caps, WSP_CAPS_CLIENT_SDU_SIZE, NULL) == 0) {
		if (wsp_cap_get_client_sdu(req, &ui) > 0) {
			/* Accept value if it is not silly. */
			if ((ui >= 256 && ui < LONG_MAX) || ui == 0) {
				m->client_SDU_size = ui;
			}
		}
		/* Reply with the client SDU we decided on */
		data = octstr_create("");
		octstr_append_uintvar(data, m->client_SDU_size);
		cap = wsp_cap_create(WSP_CAPS_CLIENT_SDU_SIZE,
			NULL, data);
		gwlist_append(caps, cap);
	}

	if (wsp_cap_count(caps, WSP_CAPS_SERVER_SDU_SIZE, NULL) == 0) {
		/* Accept whatever size the client is willing
		 * to send.  If the client did not specify anything,
		 * then use the default. */
		if (wsp_cap_get_server_sdu(req, &ui) <= 0) {
			ui = 1400;
		}
		data = octstr_create("");
		octstr_append_uintvar(data, ui);
		cap = wsp_cap_create(WSP_CAPS_SERVER_SDU_SIZE, NULL, data);
		gwlist_append(caps, cap);
	}

	/* Currently we cannot handle any protocol options */
	if (wsp_cap_count(caps, WSP_CAPS_PROTOCOL_OPTIONS, NULL) == 0) {
		data = octstr_create("");
		octstr_append_char(data, 0);
		cap = wsp_cap_create(WSP_CAPS_PROTOCOL_OPTIONS, NULL, data);
		gwlist_append(caps, cap);
	}

	/* Accept any Method-MOR the client sent; if it sent none,
	 * use the default. */
	if (wsp_cap_count(caps, WSP_CAPS_METHOD_MOR, NULL) == 0) {
		if (wsp_cap_get_method_mor(req, &ui) <= 0) {
			ui = 1;
		}
		data = octstr_create("");
		octstr_append_char(data, ui);
		cap = wsp_cap_create(WSP_CAPS_METHOD_MOR, NULL, data);
		gwlist_append(caps, cap);
	}

	/* We will never send any Push requests because we don't support
	 * that yet.  But we already specified that in protocol options;
	 * so, pretend we do, and handle the value that way. */
	if (wsp_cap_count(caps, WSP_CAPS_PUSH_MOR, NULL) == 0) {
		if (wsp_cap_get_push_mor(req, &ui) > 0) {
			m->MOR_push = ui;
		}
		data = octstr_create("");
		octstr_append_char(data, m->MOR_push);
		cap = wsp_cap_create(WSP_CAPS_PUSH_MOR, NULL, data);
		gwlist_append(caps, cap);
	}

	/* Supporting extended methods is up to the application layer,
	 * not up to us.  If the application layer didn't specify any,
	 * then we refuse whatever the client requested.  The default
	 * is to support none, so we don't really have to add anything here. */

	/* We do not support any header code pages.  sanitize_capabilities
	 * must have already deleted any reply that indicates otherwise.
	 * Again, not adding anything here is the same as refusing support. */

	/* Listing aliases is something the application layer can do if
	 * it wants to.  We don't care. */
}
Ejemplo n.º 2
0
/*
 * Our WSP headers: Push Id, PDU type, headers, charset.
 */
static int ota_pack_push_headers(Msg **msg, Octstr *mime_type, Octstr *sec, 
                                 Octstr *pin, Octstr *ota_binary)
{    
    (*msg)->sms.msgdata = octstr_create("");
    if (octstr_case_compare(mime_type, octstr_imm("settings")) == 0) {
        
        /* PUSH ID, PDU type, header length, value length */
        octstr_append_from_hex((*msg)->sms.msgdata, "01062C1F2A");
        /* MIME type for settings */
        octstr_format_append((*msg)->sms.msgdata, "%s", 
                             "application/x-wap-prov.browser-settings");
        octstr_append_from_hex((*msg)->sms.msgdata, "00");
        /* charset UTF-8 */
        octstr_append_from_hex((*msg)->sms.msgdata, "81EA");

    } else if (octstr_case_compare(mime_type, octstr_imm("bookmarks")) == 0) {
        
        /* PUSH ID, PDU type, header length, value length */
        octstr_append_from_hex((*msg)->sms.msgdata, "01062D1F2B");
        /* MIME type for bookmarks */
        octstr_format_append((*msg)->sms.msgdata, "%s", 
                             "application/x-wap-prov.browser-bookmarks");
        octstr_append_from_hex((*msg)->sms.msgdata, "00");
        /* charset UTF-8 */
        octstr_append_from_hex((*msg)->sms.msgdata, "81EA");

    } else if (octstr_case_compare(mime_type, octstr_imm("syncsettings")) == 0) {

        octstr_append_from_hex((*msg)->sms.msgdata, "3406060502020b81EA"); 

    } else if (octstr_case_compare(mime_type, octstr_imm("oma-settings")) == 0) {
        Octstr *hdr = octstr_create(""), *mac; 
        unsigned char *p;
        unsigned int mac_len;
#ifdef HAVE_LIBSSL
        unsigned char macbuf[EVP_MAX_MD_SIZE];
#endif

        /* PUSH ID, PDU type, header length, value length */
        octstr_append_from_hex((*msg)->sms.msgdata, "0106");
    
        octstr_append_from_hex(hdr, "1f2db6"); /* Content type + other type + sec param */
        wsp_pack_short_integer(hdr, 0x11);
        if (octstr_case_compare(sec, octstr_imm("netwpin")) == 0)
            wsp_pack_short_integer(hdr, 0x0);       
        else if (octstr_case_compare(sec, octstr_imm("userpin")) == 0)
            wsp_pack_short_integer(hdr, 0x01);          
        else if (octstr_case_compare(sec, octstr_imm("usernetwpin")) == 0)
            wsp_pack_short_integer(hdr, 0x02);          
        else if (octstr_case_compare(sec, octstr_imm("userpinmac")) == 0)
            wsp_pack_short_integer(hdr, 0x03); /* XXXX Although not quite supported now.*/          
        else {
            warning(0, "OMA ProvCont: Unknown SEC pin type '%s'.", octstr_get_cstr(sec));
            wsp_pack_short_integer(hdr, 0x01);          
        }
        wsp_pack_short_integer(hdr, 0x12); /* MAC */

#ifdef HAVE_LIBSSL
        p = HMAC(EVP_sha1(), octstr_get_cstr(pin), octstr_len(pin), 
                 (unsigned char *)octstr_get_cstr(ota_binary), octstr_len(ota_binary), 
                 macbuf, &mac_len);
#else
        mac_len = 0;
        p = "";
        warning(0, "OMA ProvCont: No SSL Support, '%s' not supported!", octstr_get_cstr(mime_type));
#endif
        mac = octstr_create_from_data((char *)p, mac_len);
        octstr_binary_to_hex(mac, 1);
    
        octstr_append(hdr, mac);
        octstr_append_from_hex(hdr, "00");
    
        octstr_append_uintvar((*msg)->sms.msgdata, octstr_len(hdr));
        octstr_append((*msg)->sms.msgdata, hdr);
    
        octstr_destroy(hdr);
        octstr_destroy(mac);
        
    } else {
        warning(0, "Unknown MIME type in OTA request, type '%s' is unsupported.", 
                octstr_get_cstr(mime_type));
        return 0;
    }

    return 1;
}