function param = tchParam(tchType)
% param = tchParam(tchType)
%   Returns useful traffic channel parameters for the channel type tchType.
%
%   Valid channel types are:
%       'afs'       AMR full-rate speech
%       'fs'        GSM full-rate speech 
%
% Copyright 2008, Research In Motion Limited.

    % NOTE: By convention, the last two modes are 'SID' and 'NODATA'
    afsModes = { ...
        '4p75', '5p15', '5p9', '6p7', '7p4', ...
        '7p95', '10p2', '12p2', 'SID', 'NODATA' ...
    };
    afsClassBits = { ...
        [1:39], [40:95], []; ...
        [1:49], [50:103], []; ...
        [1:55], [56:118], []; ...
        [1:55], [56:134], []; ...
        [1:61], [62:148], []; ...
        [1:75], [76:159], []; ...
        [1:65], [66:204], []; ...
        [1:81], [82:244], []; ...
        [1:35], [], []; ...
        [], [], []; ...
    };
    fsModes = {'13p0', 'SID', 'NODATA'};
    fsClassBits = { ...
        [1:50], [51:182], [183:260]; ...
        [1:50], [51:182], [183:260]; ...
        [], [], []; ...
    };
    hsModes = {'5p6', 'SID', 'NODATA'};
    hsClassBits = {
        [1:22], [23:95], [96:112]; ...
        [1:22], [23:95], [96:112]; ...
        [], [], []; ...
    };

    types = {'afs', 'wfs', 'efs', 'fs', 'ahs', 'whs', 'hs'};
    codecs = {'amr', 'amr-wb', 'efr', 'fr', 'amr', 'amr-wb', 'hr'};
    modes = {afsModes, [], [], fsModes, [], [], hsModes};
    classBits = {afsClassBits, [], [], fsClassBits, [], [], hsClassBits};

    % Split tchType into type and mode
    i = find(tchType >= '0' & tchType <= '9');
    if ~isempty(i)
        type = tchType(1:i-1);
        mode = tchType(i:end);
    else
        type = tchType;
        mode = [];
    end

    % Lookup type and mode(s)
    iType = strmatch(type, types, 'exact');
    if isempty(iType)
        error('Invalid tchType ''%s''', tchType);
    elseif isempty(modes{iType})
        error('tchType ''%s'' is currently unsupported', tchType);
    end
    if isempty(mode)
        iModes = 1:length(modes{iType});
    else
        iModes = strmatch(mode, modes{iType}, 'exact');
        if isempty(iModes)
            error('Invalid mode ''%s'' for ''%s''', mode, type);
        end
    end

    param = struct();
    param.codec = codecs{iType};
    param.tchType = type;
    param.tchModes = modes{iType}(iModes);
    param.classBits = classBits{iType}(iModes, :);
end
