Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id: sock_qos_wm.c 3553 2011-05-05 06:14:19Z nanang $ */ |
| 2 | /* |
| 3 | * Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #include <pj/sock_qos.h> |
| 20 | #include <pj/assert.h> |
| 21 | #include <pj/errno.h> |
| 22 | #include <pj/log.h> |
| 23 | |
| 24 | #include <winsock.h> |
| 25 | |
| 26 | /* QoS implementation for Windows Mobile 6, must be enabled explicitly |
| 27 | * (this is controlled by pjlib's config.h) |
| 28 | */ |
| 29 | #if defined(PJ_QOS_IMPLEMENTATION) && PJ_QOS_IMPLEMENTATION==PJ_QOS_WM |
| 30 | |
| 31 | #define THIS_FILE "sock_qos_wm.c" |
| 32 | |
| 33 | /* Mapping between our traffic type and WM's DSCP traffic types */ |
| 34 | static const int dscp_map[] = |
| 35 | { |
| 36 | DSCPBestEffort, |
| 37 | DSCPBackground, |
| 38 | DSCPVideo, |
| 39 | DSCPAudio, |
| 40 | DSCPControl |
| 41 | }; |
| 42 | |
| 43 | PJ_DEF(pj_status_t) pj_sock_set_qos_params(pj_sock_t sock, |
| 44 | pj_qos_params *param) |
| 45 | { |
| 46 | PJ_UNUSED_ARG(sock); |
| 47 | PJ_UNUSED_ARG(param); |
| 48 | |
| 49 | PJ_LOG(4,(THIS_FILE, "pj_sock_set_qos_params() is not implemented " |
| 50 | "for this platform")); |
| 51 | return PJ_ENOTSUP; |
| 52 | } |
| 53 | |
| 54 | PJ_DEF(pj_status_t) pj_sock_set_qos_type(pj_sock_t sock, |
| 55 | pj_qos_type type) |
| 56 | { |
| 57 | int value; |
| 58 | |
| 59 | PJ_ASSERT_RETURN(type < PJ_ARRAY_SIZE(dscp_map), PJ_EINVAL); |
| 60 | |
| 61 | value = dscp_map[type]; |
| 62 | return pj_sock_setsockopt(sock, IPPROTO_IP, IP_DSCP_TRAFFIC_TYPE, |
| 63 | &value, sizeof(value)); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | PJ_DEF(pj_status_t) pj_sock_get_qos_params(pj_sock_t sock, |
| 68 | pj_qos_params *p_param) |
| 69 | { |
| 70 | PJ_UNUSED_ARG(sock); |
| 71 | PJ_UNUSED_ARG(p_param); |
| 72 | |
| 73 | PJ_LOG(4,(THIS_FILE, "pj_sock_get_qos_params() is not implemented " |
| 74 | "for this platform")); |
| 75 | return PJ_ENOTSUP; |
| 76 | } |
| 77 | |
| 78 | PJ_DEF(pj_status_t) pj_sock_get_qos_type(pj_sock_t sock, |
| 79 | pj_qos_type *p_type) |
| 80 | { |
| 81 | pj_status_t status; |
| 82 | int value, optlen; |
| 83 | unsigned i; |
| 84 | |
| 85 | optlen = sizeof(value); |
| 86 | value = 0; |
| 87 | status = pj_sock_getsockopt(sock, IPPROTO_IP, IP_DSCP_TRAFFIC_TYPE, |
| 88 | &value, &optlen); |
| 89 | if (status != PJ_SUCCESS) |
| 90 | return status; |
| 91 | |
| 92 | *p_type = PJ_QOS_TYPE_BEST_EFFORT; |
| 93 | for (i=0; i<PJ_ARRAY_SIZE(dscp_map); ++i) { |
| 94 | if (value == dscp_map[i]) { |
| 95 | *p_type = (pj_qos_type)i; |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return PJ_SUCCESS; |
| 101 | } |
| 102 | |
| 103 | #endif /* PJ_QOS_IMPLEMENTATION */ |